fn to split concatenated and delimited string into seperate column of 2 tables

  • Hi guys,

    I am using sql server 2005

    Need a function to split concatenated and delimited string into seperate columns

    Input to the function is one string like:

    Fn('code1-Region1, code1-Region2, code2-region1')

    in the above Concatenation is '-' and delimiter is ','

    Need output into two tables like:

    OutputTable1

    --------------------

    codecol

    -----------

    code1

    code2

    ....

    ....

    ---------------------

    OutputTable2

    ----------------------

    Regioncol

    -----------

    Region1

    Region2

    ....

    ....

    -----------------------

    Thanks

  • I'd recommend a two-step approach...

    1. split the string into the comma-separated portion into a column in a temp table

    2. split the column with the dash-separated columns

    You might want to take a look at this thread. It is doing a lot of what you're looking for.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

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

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