- /**
- QS:在mssqlserver2000中一个表中有两条记录
- a,a,0,0,b,0,c,0
- 0,0,b,0,0,d,0,0
- 如何将这两条记录合并为
- a,a,b,0,b,d,c,0
- **/
- /*AS:-sql05*/
- --建立测试表
- Create TABLE # (id1 varchar(10), id2 varchar(10),id3 varchar(10),
- id4 varchar(10),id5 varchar(10),id6 varchar(10),id7 varchar(10),id8 varchar(10) )
- INSERT # SELECT 'a','a','0','0','b','0','c','0'
- UNION ALL SELECT '0','0','b','0','0','d','0','0'
- --
- select * from #
- /*
- id1 id2 id3 id4 id5 id6 id7 id8
- a a 0 0 b 0 c 0
- 0 0 b 0 0 d 0 0
- */
- --
- select max(id1) id1,
- max(id2) id2,
- max(id3) id3,
- max(id4) id4,
- max(id5) id5,
- max(id6) id6,
- max(id7) id7,
- max(id8) id8
- from #
- /*
- id1 id2 id3 id4 id5 id6 id7 id8
- a a b 0 b d c 0
- */