Derived Columns= Please help- Important

  • I need help on seperating the following one column information into two columns; For example

    ---Current Data

    PMSA

    (560028) NEW YORK, NY PMSA

    (-9) UNDESIGNATED AREA/MISSING/UNKNOWN/NOT COLLECTED/INVALID

    (4) UNDESIGNATED AREA/MISSING/UNKNOWN/NOT COLLECTED/INVALID

    ----Need to seperate into two columns

    PMSA_CODE PMSA_DESC

    560028 NEW YORK, NY PMSA

    -9 UNDESIGNATED AREA/MISSING/UNKNOWN/NOT COLLECTED/INVALID

    4 UNDESIGNATED AREA/MISSING/UNKNOWN/NOT COLLECTED/INVALID

  • The only difference between the two sets that I see is that you have removed the parenthesis.

    What are the desired columns?

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Here is one way of performing what I think you want. Now it is not the most efficient way, so if you have 100,000s of rows in your table it will be rather slow.

    CREATE TABLE #T(PMSA_CODE VARCHAR(100))

    INSERT INTO #T (PMSA_CODE)

    SELECT '(560028) NEW YORK, NY PMSA'

    UNION ALL

    SELECT '(-9) UNDESIGNATED AREA/MISSING/UNKNOWN/NOT COLLECTED/INVALID' UNION ALL

    SELECT '(4) UNDESIGNATED AREA/MISSING/UNKNOWN/NOT COLLECTED/INVALID'

    SELECT SUBSTRING(PMSA_CODE,2,CHARINDEX (')',PMSA_CODE,2)-2)

    ,SUBSTRING(PMSA_CODE,CHARINDEX (')',PMSA_CODE,2)+1,DATALENGTH(PMSA_CODE))

    FROM #T

    -- DROP TABLE #T

    some results:

    560028 NEW YORK, NY PMSA

    -9 UNDESIGNATED AREA/MISSING/UNKNOWN/NOT COLLECTED/INVALID

    4 UNDESIGNATED AREA/MISSING/UNKNOWN/NOT COLLECTED/INVALID

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Thank you so much for reply, but I need to use the substring in SSIS package. If you can provide me the command or transformation option to seperate the different number values to a seperate column that would be greate.

  • Use a tsql object and execute the script already provided.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • It looks like you are trying to separate the leading number from the rest of the data. If so, try this.

    SUBSTRING( YourFieldDataHere, 2, FINDSTRING( YourFieldDateHere, ")", 1) -2)

  • Yes, You are my life saver... I will try and let you know. Than ks

  • Thanks a lot! It did work!

Viewing 8 posts - 1 through 7 (of 7 total)

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