Home Forums SQL Server 2008 T-SQL (SS2K8) Help needed to decode comma delimited string and insert into tables RE: Help needed to decode comma delimited string and insert into tables

  • jinghua.ji (2/17/2011)


    Hi all,

    Recently, I was working on turning structured audit string into a table

    sample string 1:

    ,2 Column_Name "Col1" "Col2" , 2 New_Column_Value "A" "B" , 2 Old_Column_Value "a" "b"

    sample result 1:

    field_type field_name new_value old_value

    column Col1 A a

    column Col2 B b

    sample string 2:

    ,2 Field_Name "F1" "F2", 2 New_Field_Name "F1" "F2", 2 Old_Field_Name "f1" "f2" ,1 Column_Name "Col3" ,1 New_Column_Value "C", 1 Old_Column_Value "c"

    sample result 2:

    field_type field_name new_value old_value

    field F1 F1 f1

    field F2 F2 f2

    column Col3 C c

    the string does not limit the number of field or column changes, so it can be 100,000 :sick:

    I have a script on hand that uses cursor which takes an awful long time. I also tried tally table, but it does not fit.

    Has anyone faced this issue before? or can anyone help me? thanks

    No problem. Please post your Tally Table based code (because it will more closely identify the goal of the code) and let's have a go at it.

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