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 2012 Forums
 Transact-SQL (2012)
 query -stuff

Author  Topic 

kt
Yak Posting Veteran

88 Posts

Posted - 2015-02-03 : 15:30:17
Hi,

Result # 1 is what is currently showing. I would like my query returns the results like # 2 . Please tell me what have wrong from the query below? - Thanks

select failedID,stuff((select ','+b.sName from [dbo].[SCName] b where a.Id_int = b.id_int for xml path('')),1,1,'') as 'name'
from [dbo].[Reason] a

FailedID name
1 AA
2 BB
3 CC
4 DD
4 EE
4 FF



FailedID name
1 AA
2 BB
3 CC
4 DD,EE,FF

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-02-03 : 15:42:22
try adding "group by failedid"
Go to Top of Page

kt
Yak Posting Veteran

88 Posts

Posted - 2015-02-03 : 16:50:10
did not work
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-02-03 : 19:19:29
quote:
Originally posted by kt

did not work



Post your modified query along with some sample data
Go to Top of Page
   

- Advertisement -