Results 1 to 3 of 3
  1. #1
    cad4321 Guest

    Question MSSQL: Concatenate many rows into a single string

    Hi,

    I have a table as below. It is just a sample.


    Sales Amt Sales Person
    ------------ ---------------
    142 Mary
    142 John
    142 Sam
    222 Alaina
    222 Edward

    I want to get it as

    Sales Amt Sales Person
    ------------ ---------------
    142 Mary, John, Sam
    222 Alaine, Edward

  2. #2
    RonR Guest

    Default

    Sweet .... I remember i had a similar problem which i solved through interface language instead of SQL. Very tiresome ..... Anyhow time changed .... Here is how you can do it. You lucky Man!

    Code:
    Select distinct ST2.SAmt, 
                   substring((Select ','+ST1.SName AS [text()]
                    From dbo.Salers ST1
                    Where ST1.SAmt = ST2.SAmt
                    ORDER BY ST1.SAMT
                    For XML PATH ('')),2, 1000) [Sales]
             From dbo.Sales ST2

  3. #3
    cad4321 Guest

    Default

    Thank you very much.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •