-1

I have a query with results shown below. As you can see, the grp_code column is the same.

I want to make a string out of the find_description column and have the results show in one column. I have several items like this and I am hoping there is a simple method.

Group Description          Grp Code        Find Code           Find description
Pre Procedure              CENTL8          FND102757           Labs Reviewed
Pre Procedure              CENTL8          FND102758           Consent verified
Pre Procedure              CENTL8          FND102759           History
Pre Procedure              CENTL8          FND120760           Assemble equipment

Result needed

Labs Reviewed, Consent Verified, History, Assemble equipment
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Don Ward
  • 1
  • 1
  • 1
    What attempt have you made at this? What are your column and table names called so someone can help put the query together for you. Have you googled building a string delimited list column in order to attempt this on your own? – Jt2ouan Dec 05 '14 at 15:55

1 Answers1

0

You would use the stuff function and xml path to build a string delimited list column.

  SELECT
     Group_description
     ,Grp_code
     ,Find_code
     ,find_descriptionString = STUFF((
          SELECT ', ' + md.find_description
          FROM *table_name*
          WHERE m.group_code = md.group_code
          FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '')
FROM *table_name* m
GROUP BY m.grp_code
         ,group_description
         ,find_code
Jt2ouan
  • 1,964
  • 9
  • 33
  • 55