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 |
|
itnagaraj
Yak Posting Veteran
70 Posts |
Posted - 2011-07-04 : 07:50:41
|
| The SQL & result set is below.Select Attachmentname From tblAttachments Where RequestId=358 Order By Id AscAttachmentname--------------Alter query.xlsxIssue Id_28.JPGSo i want sql for below format.The result set is change dynamically.Attachmentname --------------Alter query.xlsx,Issue Id_28.JPGHow to write.Pls helpV.NAGARAJAN |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-07-04 : 15:46:26
|
| ;with cte as(select Attachmentname , seq = row_number() over (order by id)from tblAttachments Where RequestId=358)select t1.Attachmentname + ',' + t2.Attachmentname from ct1 t1, cte t2where t1.seq = 1 and t2.seq = 2==========================================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 - 2011-07-05 : 13:45:39
|
| [code]select stuff((select ',' + Attachmentname from tblAttachments order by Id Asc for xml path('')),1,1,'')[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|