Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concatenate multiple rows into a single row

Status
Not open for further replies.

arodri

Technical User
Jul 9, 2010
121
US
I'm not sure how (or if it's possible) to concatenate the data in the way that I need it.
Here's a sample of my data:

Service1 Serivce 2 Service 3 Code Date
NULL TS NULL 05S6 2011-01-09 00:00:00
FS NULL NULL 05S6 2011-01-09 00:00:00
Null Null AF 05S6 2011-01-09 00:00:00

Here's what I need the data to look like:
Service1 Serivce 2 Service 3 Code Date
FS TS AF 05S6 2011-01-09 00:00:00

I need only one row per DATE and per CODE, and I need all of the services for that particular Date and Code on that ONE row. How can I approach this?

Eventually I need the data to look like this (but I think I can just use "+" once I get all of the data in one row):

ServicesPerformed Code Date
FS,TS,AF 05S6 2011-01-09 00:00:00



 
If you were going to have only 1 value in each column you could do the following.

Code:
SELECT max(A.Service1), max(A.Service2), max(A.Service3), A.Code, A.DTE
FROM YourTable A
group by A.DTE, A.Code
 
there are several examples with the "for xml path" and it is the best.

Simi
 
Thanks for your help! I had to take a different route in the query but if this comes up again I'll know :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top