现在表abc
字段
id name
1 a
2 b
3 c
4 d
写SQL语句转换成
id name id name
1 a 2 b
3 c 4 d
语句:
本人经过多次也没有找到更好的办法,现写下下面这个方法进行实现,如有哪位网友有好方法,望附上!:)
if (select object_id('tempdb..#a')) is not null
drop table #a
if (select object_id('tempdb..#b')) is not null
drop table #b
select identity(int,1,1) as iid,id,name into #a from abc where id%2<>0
select identity(int,1,1) as iid,id,name into #b from abc where id%2=0
select #a.id,#a.name,#b.id,#b.name from #a left outer join #b on #a.iid=#b.iid