;WITH cte AS
(
select id,student,code,[desc],
ROW_NUMBER()OVER(PARTITION BY id ORDER BY (select null)) as rn
from #table1 as t
)
--select * from cte
,cteRN AS
(
select id,student,code,[desc],rn,(rn-1)/2 as joinRn, rn%2 as restRn
from cte
)
--select * from cteRN
Select isnull(a.id,b.id) as id
,isnull(a.student,b.student) as student
,a.code,a.[desc]
,b.code,b.[desc]--,a.rn,b.rn,a.restRn,b.restRn
from (select id,student,code,[desc],rn, joinRn from cteRN where restRn = 1 ) as a
full join (select id,student,code,[desc],rn, joinRn from cteRN where restRn = 0 ) as b
on a.id = b.id
and a.joinRn = b.joinRN
and a.rn <> b.rn
order by isnull(a.id,b.id)