How to get multiple of Rows of data into one single row in the CSV format

  • Is it possible to get the multiple rows of data into one single row in SSRS 2005/2008/2008R2?

    For instance, if I've a data that looks like

    ID

    104

    105

    106

    108

    Now, I want it to look like

    ID

    104,105,106,108

    Right now, I just wanted to know if we can do this in any versions of SSRS, using the experssions.

    Any guidance is much appreciated.

    Thanks.

  • This pattern will work in SQL when you are only dealing with a single column of data.

    USE AdventureWorks

    GO

    DECLARE @listStr VARCHAR(MAX)

    SELECT @listStr = COALESCE(@listStr+',' ,'') + Name

    FROM Production.Product

    SELECT @listStr

    GO

  • For a bit more detail on the subject, please see the following article...

    http://www.sqlservercentral.com/articles/comma+separated+list/71700/

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Resolved the issue in TSQL using the CTE.

    Thanks everyone for your suggestion and help 🙂

  • sbj1411 (4/10/2012)


    Resolved the issue in TSQL using the CTE.

    Thanks everyone for your suggestion and help 🙂

    Would you post your code, please? It might help someone else. Thanks.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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