March 22, 2016 at 10:21 am
Hi
The code below get the data I need but I want to comma separate the dbo.[common Items].Name field grouped by dbo.[Progress Note Common Selections].Parent
Fairly sure I need the STUFF command just not sure how to set it up,
SELECT dbo.[Progress Note Common Selections].Parent,
CASE WHEN dbo.[common Items].Name = 'other' THEN 'Other: ' + dbo.[Progress Note Common Selections].OtherText ELSE dbo.[Common Items].Name
END AS present
FROM dbo.[Progress Note Common Selections] INNER JOIN
dbo.[Common Items] ON dbo.[ Progress Note Common Selections].Item = dbo.[Common Items].ID INNER JOIN
dbo.[Common Item Categories] ON dbo.[Common Items].Category = dbo.[Common Item Categories].ID
ORDER BY dbo.[Progress Note Common Selections].Parent, present
MY output looks like
parent Present
11111 Client
11111 other:Parent
I would like ...
parent Present
11111 Client, other:Parent
Thanks in advance
Joe
March 22, 2016 at 10:27 am
Joe
The easiest way is to use a FOR XML clause in your SELECT statement. There are lots of examples out there - search for concatentate aggregate function. You'll probably need STUFF, but only to remove the trailing delimiter.
John
March 22, 2016 at 10:59 am
Read the following article: http://www.sqlservercentral.com/articles/comma+separated+list/71700/
It explains what each part does. Be sure to understand how it works and ask any questions you might have. You could also read BOL to understand what the functions do.
March 22, 2016 at 11:58 am
Thank you.. I am looking/looking up these now
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply