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.
Author |
Topic |
cmosii
Starting Member
1 Post |
Posted - 2012-07-05 : 05:26:05
|
Hi ...I have a table which contains ROW1 ROW2ID File============1 1.file2 2.file3 3.file4 4.file5 5.file6 6.file7 7.file8 8.file============is it possible to show it in the following formatRow1 Row2 Row31.file 2.file 3.file4.file 5.file 6.file7.file 8.file...etcThank you for your cooperation |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-07-05 : 05:47:52
|
something likeselect a1.file, a2.file, a3.file(select *, seq = id/3 from tbl where id%3 = 1) a1left join (select *, seq = id/3 from tbl where id%3 = 2) a2on a2.seq = a1.seqleft join (select *, seq = id/3 from tbl where id%3 = 0) a3on a3.seq = a1.seq==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-05 : 10:06:20
|
[code]SELECT MAX(CASE WHEN Rn=1 THEN File END) AS Row1,MAX(CASE WHEN Rn=2 THEN File END) AS Row2,MAX(CASE WHEN Rn=3 THEN File END) AS Row3FROM (SELECT ROW_NUMBER() OVER (PARTITION BY (ID-1)/3 ORDER BY ID) AS Rn,(ID-1)/3 AS Grp,*FROM Table)tGROUP BY Grp [/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|