Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Group Values in TSQL Expand / Collapse
Author
Message
Posted Thursday, November 8, 2012 3:30 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, June 3, 2014 4:20 AM
Points: 66, Visits: 363
Hello,

How can i merge same fields different values to one value?


eg. tblEmployee table and output is,

Date Employee Summary
07/11/2012 Susan Job 1 Done
07/11/2012 Susan Job 2 Done
07/11/2012 Mike Job 11 Done
07/11/2012 Mike Job 12 Done


Desire Output:

Date Employee Summary
07/11/2012 Susan Job 1 Done and Job 2 Done
07/11/2012 Mike Job 11 Done and Job 12 Done

Post #1382369
Posted Thursday, November 8, 2012 3:48 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, July 4, 2014 3:55 AM
Points: 2,836, Visits: 5,062
google:
T-SQL concatenate string FOR XML PATH


_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1382378
Posted Thursday, November 8, 2012 3:48 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 4:59 PM
Points: 275, Visits: 1,665
No EmployeeId? Why? You might have two employees with the same name..

SELECT DISTINCT
EmployeeId ,
Date ,
Employee ,
STUFF(( SELECT ' and ' + t2.Summary AS [text()]
FROM tblEmployee t2
WHERE t2.EmployeeId = t1.EmployeeId
FOR
XML PATH('')
), 1, 5, '') AS Summary
FROM tblEmployee t1

Post #1382379
Posted Thursday, November 8, 2012 4:03 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, June 3, 2014 4:20 AM
Points: 66, Visits: 363
You are Super Star clayman, make my day

There is EmployeeID, it was just example and in a rush didn't define.

Thanks Again.
Post #1382383
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse