• spin (11/7/2013)


    Hi

    i have the following field in a progress db which contains analysis codes for a given account. I need to split the codes into their own columns.

    here's an example: 007;007;01D;P;999;999;

    I am using the following to get the position of the ; character and then using substing to try and pull out the parts. The code is becoming painful already though and i'm only at the 3rd code.

    Is there an easier way to do this?

    charindex(';', analcode) pos1,

    charindex(';', analcode, charindex(';',analcode)+1) pos2,

    charindex(';', analcode, charindex(';', analcode, charindex(';',analcode)+1)+1) pos3

    Thanks

    Take a look at the link in my signature about splitting strings. It will show a super easy and fast way to do this.

    Also, I might suggest changing the name of your column. 😛

    _______________________________________________________________

    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/