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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQl Query Help

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 Asc

Attachmentname
--------------
Alter query.xlsx
Issue Id_28.JPG

So i want sql for below format.The result set is change dynamically.
Attachmentname
--------------
Alter query.xlsx,Issue Id_28.JPG

How to write.Pls help


V.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 t2
where 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.
Go to Top of Page

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 MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -