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.
Hi ALLI have the below query which concatenates the comments feild in a table and separates it by a coma.Is it possible to add sequential numbers for each comments
SELECT DISTINCT ReqNo,STUFF(( SELECT ',' + COMMENTSFROM Concatenating_comments WHERE ReqNo= T.ReqNoFOR XML PATH('') ),1,1,'') AS AGGREGATEDCOMMENTSFROM Concatenating_comments T
ThanksJim
webfred
Master Smack Fu Yak Hacker
8781 Posts
Posted - 2012-01-06 : 09:20:20
without a test but it should work:
SELECT DISTINCT ReqNo,STUFF(( SELECT ',' + convert(varchar(10),rnum) + '. ' + COMMENTS FROM (select row_number() over (order by ReqNo asc) as rnum, comments, ReqNo from Concatenating_comments) as Concatenating_comments WHERE ReqNo= T.ReqNo FOR XML PATH('') ),1,1,'') AS AGGREGATEDCOMMENTSFROM Concatenating_comments T
No, you're never too old to Yak'n'Roll if you're too young to die.