Returning Multiple Columns - T SQL

  • Hi

    I have a comma delimited values and I want to split this values into mulitple columns. Can someone share the idea / scripts?

    Ex

    Input

    @v-2 = 'A,B,C'

    Output

    Col1 Col2 Col3

    A B C

    Thanks

    Shuaib

  • I'd look at the split method in .Net to create an array for this. Otherwise you might get stuck with some cheesy TSQL string manipulation.

  • ab5sr (6/25/2009)


    I'd look at the split method in .Net to create an array for this. Otherwise you might get stuck with some cheesy TSQL string manipulation.

    I know this is an older post but Cheesy? Heh... you must not know how to do it in T-SQL. 😉

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

  • Shuaib (6/25/2009)


    Hi

    I have a comma delimited values and I want to split this values into mulitple columns. Can someone share the idea / scripts?

    Ex

    Input

    @v-2 = 'A,B,C'

    Output

    Col1 Col2 Col3

    A B C

    Thanks

    Shuaib

    At the risk of being almost a month late to help keep the cheese from stinking too bad ;-), do you still need some help on this? Despite the current sentiment, there are some methods to do this that will rival even a very well formed CLR or (ugh!) a trip to the .Net cottage.

    Also, will you always have a fixed number of items to split (ie, 3) or does it need to produce a variable result?

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

  • Jeff Moden (7/20/2009)


    ab5sr (6/25/2009)


    I'd look at the split method in .Net to create an array for this. Otherwise you might get stuck with some cheesy TSQL string manipulation.

    I know this is an older post but Cheesy? Heh... you must not know how to do it in T-SQL. 😉

    LOL I guess I don't. Have they added SPLIT() to the TSQL syntax? I'll have to look it up, right.

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

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