Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
SOURCE TABLEID SEQ COM VARCHAR(10)1 1 I1 2 am1 3 doctor2 1 I 2 2 am nurse DESTINATION TABLE --Each comm field is varchar(20)ID_COM1___COM2______COM31__I______am_________doctor 2__I______am nurse____NULL Please Help
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2008-06-11 : 10:33:41
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254MadhivananFailing to plan is Planning to fail
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2008-06-11 : 10:46:04
If you're sure that you'll have maximum of 3 records per each ID then you can do like this also
SELECT ID,MAX(CASE WHEN SEQ=1 THEN COM ELSE NULL END) AS COM1,MAX(CASE WHEN SEQ=2 THEN COM ELSE NULL END) AS COM2,MAX(CASE WHEN SEQ=3 THEN COM ELSE NULL END) AS COM3FROM SourceTableGROUP BY ID
awalsql
Starting Member
11 Posts
Posted - 2008-06-11 : 10:46:57
Hi But I am using sql2000. Is there any easy way to do this in sql 2000.
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2008-06-11 : 11:05:01
Did you follow visakh?MadhivananFailing to plan is Planning to fail