Group Values in TSQL

  • 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

  • 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[/url]

  • 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

  • You are Super Star clayman, make my day 🙂

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

    Thanks Again.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply