Join rows of a column in One

  • Hey Guys,

    If I am not mistaken I was able to do this in the past but now I don't remember how I did it. And I need some help:D to remember...

    I have a table similar to this:

    MyTable1

    ------------------------------

    ColA ColB

    ------------------------------

    a |1

    a |2

    a |3

    b |5

    b |6

    b |7

    My Query result should look like:

    colAcolB

    -------------------------

    a 1,2,3

    b5,6,7

    I would love to have these in the least staments posible. If I can avoid building a SQL function for this will be great.

    This is the closest I get:

    Declare @col2 VARCHAR(800)

    SET @col2 = ''

    SELECT @col2 = @col2 + Col2 + ','

    FROM MyTable1..

    But to be honest I remember what I did in the past was simpler than that.... becuase after that query I am forced to create a function.

    Does anyone know?

  • did you check Jeff's concatenation article ?

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

    If not, you realy should 😉

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

Viewing 2 posts - 1 through 1 (of 1 total)

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