To get rows in CSV format

  • Hi, I have two fields State and City in one table. When I select I get

    STATE CITY

    Connecticut Hartford

    Connecticut Stamford

    Connecticut New Haven

    Connecticut Bridgeport

    But I need in CSV format, like

    ConnecticutHartford, Stamford, New Haven, Bridgeport

    There are many cities for some states. At my work place we can’t use dynamic sql. So can anybody suggest me the best way to do it?

  • Instead of posting in TSQL forum I posted here. So please forgive me.

  • See the following for a basic "how to" and some pitfalls to avoid...

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

    ... and, in most cases, the biggest pitfall is the task itself. CSV data shouldn't be stored in a database because it violates the first form of nomalization. I can see it, maybe, for file creation.

    --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)

  • Hi, I saw that article and tried but its not working. Its giving me null values.

  • Shree (10/14/2008)


    Hi, I saw that article and tried but its not working. Its giving me null values.

    What did you try? Please post the code and the data you tried with.

    --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 4 (of 4 total)

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