SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Group Values in TSQL


Group Values in TSQL

Author
Message
Conficker
Conficker
SSC Veteran
SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)

Group: General Forum Members
Points: 249 Visits: 386
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
Eugene Elutin
Eugene Elutin
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12584 Visits: 5478
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!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
kiril.lazarov.77
kiril.lazarov.77
SSC Eights!
SSC Eights! (902 reputation)SSC Eights! (902 reputation)SSC Eights! (902 reputation)SSC Eights! (902 reputation)SSC Eights! (902 reputation)SSC Eights! (902 reputation)SSC Eights! (902 reputation)SSC Eights! (902 reputation)

Group: General Forum Members
Points: 902 Visits: 2248
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


Conficker
Conficker
SSC Veteran
SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)

Group: General Forum Members
Points: 249 Visits: 386
You are Super Star clayman, make my day :-)

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

Thanks Again.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search