Home Forums SQL Server 7,2000 T-SQL Csv list in column to separate columns RE: Csv list in column to separate columns

  • Eliza (9/18/2012)


    Jeff Moden (9/17/2012)


    Eliza (9/17/2012)


    Hi all,

    Can I ask please if I have a row and one column has a csv list in it. Is there a way please to split the csv list into columns in a row?

    For example if I have

    1 - Apple, Pear, Orange

    2. - Pear, Apple, Bananna

    In my output I would like

    Col1. Col2. Col3

    1 Apple__Pear____Orange.

    2 Pear___Apple___Bananna

    Sorry underscores are meant to split the columns.

    Thank you

    Eliza

    Are the number of elements in each CSV fixed or variable with in the same column?

    The number can vary, however it will be between 0 (null value) and a maximum of 25. It won't go higher than 25.

    Take a look at the link in my signature to the article Jeff wrote for doing just such a thing (splitting a string). Don't just copy and paste the code. Make sure you read it and UNDERSTAND it.

    --Edit--

    Bit by the spelling bug again.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/