user3666224
user3666224

Reputation: 71

Combine two rows into One Column

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

Upvotes: 0

Views: 583

Answers (2)

Jayanti Lal
Jayanti Lal

Reputation: 1185

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

Upvotes: 0

Gaston Flores
Gaston Flores

Reputation: 2467

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

Upvotes: 1

Related Questions