hi aggregate text values

  • hi to all is it possible to do like this

    DECLARE @Tbl AS TABLE (Mid INT,Sid INT, Val VARCHAR(10))

    INSERT INTO @Tbl VALUES(1,1,'A')

    INSERT INTO @Tbl VALUES(1,2,'A')

    INSERT INTO @Tbl VALUES(1,3,'D')

    INSERT INTO @Tbl VALUES(1,4,'X')

    INSERT INTO @Tbl VALUES(2,1,'A')

    INSERT INTO @Tbl VALUES(2,2,'A')

    INSERT INTO @Tbl VALUES(2,3,'C')

    INSERT INTO @Tbl VALUES(2,4,'D')

    SELECT * FROM @Tbl

    i need a result LIKE this

    1 A,D,X

    2 A,C,D

    is it possible

    Every rule in a world of bits and bytes, can be bend or eventually be broken
    MyBlog About Common dialog control
    A Visualizer for viewing SqlCommand object script [/url]

  • What would be your expected output for

    INSERT INTO @Tbl VALUES(1,1,'A')

    INSERT INTO @Tbl VALUES(1,2,'D')

    INSERT INTO @Tbl VALUES(1,3,'X')

    INSERT INTO @Tbl VALUES(1,4,'A')



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • Don't ask me exactly how this works, but a Big Hat Tip to Jeff Moden here :cool::

    SELECT t1.Mid,

    STUFF((SELECT DISTINCT(',' + t2.Val)

    FROM @Tbl t2

    WHERE t1.Mid = t2.Mid FOR XML PATH('')),1,1,'')

    FROM @Tbl t1

    GROUP BY t1.Mid

    see http://www.sqlservercentral.com/articles/Test+Data/61572/

    The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking

  • that's Really great i read that article such a wonder full information lot of thanks

    Every rule in a world of bits and bytes, can be bend or eventually be broken
    MyBlog About Common dialog control
    A Visualizer for viewing SqlCommand object script [/url]

  • thava (9/9/2010)


    that's Really great i read that article such a wonder full information lot of thanks

    'Glad to help - thanks!

    The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking

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

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