0

I have query that produces the following results:

GUID      ClientGUID          TASK                  VALUE

========================================================================

123   15757400200       Dollar Unit            Consult Time 15 Min (Quantity):1
123   15757400200       Dollar Unit            Patient/Family Education 15 min 
456   15757400200       Swallow Clarification  Swallow therapy 30 min (Qty):1

I would like to obtain the below results:

GUID     ClientGUID      TASK                 VALUE

123     15757400200   Dollar Unit            Consult Time 15 Min (Quantity):1 ;  Patient/Family Education 15 min (Qty):1
456     15757400200   Swallow Clarification  Swallow therapy 30 min (Qty):1
  • 3
    You can follow the pattern in this other Stack Exchange post http://stackoverflow.com/questions/5031204/does-t-sql-have-an-aggregate-function-to-concatenate-strings/5031297#5031297 – grambo25 Jul 29 '16 at 20:20

2 Answers2

1

Maybe this script will be useful:

SELECT GUID, ClientGUID, TASK, 
STUFF(( SELECT  ';' + VALUE FROM YOUR_TABLE a
WHERE b.GUID = a.GUID FOR XML PATH('')),1 ,1, '') AS NEW_VALUE
FROM YOUR_TABLE b
GROUP BY GUID, ClientGUID, TASK
Gaston Flores
  • 2,457
  • 3
  • 23
  • 42
0

You can use STUFF to get desired result.

     STUFF( ( SELECT  ',' +  VALUE
                    FROM tablename  where "put your condition here"
                    FOR XML PATH ('')  ) , 1,1,'') AS value
Jayanti Lal
  • 1,175
  • 6
  • 18
  • What's with the use of `NOLOCK`? And did you see Gaston's answer? – sstan Jul 29 '16 at 20:58
  • I didn't see below code..:) I have updated my code..i used NOLOCK so that even in case of table is under update mode query will be able to get records – Jayanti Lal Jul 29 '16 at 21:01
  • [Bad habits : Putting NOLOCK everywhere](http://blogs.sqlsentry.com/aaronbertrand/bad-habits-nolock-everywhere/) – sstan Jul 29 '16 at 21:53