Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2010
    Posts
    153

    Red face Unanswered: Column Values into comma separated row

    Hi,

    I have some column values:-

    employee_salary | dept

    30000 1
    35000 1
    40000 1


    I need employee-salary in one row separated by comma by executing a sql query i.e

    dept1_salary

    30000, 40000, 50000

    A SQL query would be very helpful.


    Thanks

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    Code:
    DECLARE @foo varchar(max) = ''
    
    SELECT @foo = @foo + column_name +', '
    FROM TABLE_NAME
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

Posting Permissions

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