Professional Web Applications Themes

How to unconcatenate a column - Microsoft SQL / MS SQL Server

Hi, I need to unconcatenate a column eg _b_234_5_cdv_xyz (no fixed length) into 6 different columns. The underscore is the separator. What would be the most efficient way to do this. Samy...

  1. #1

    Default How to unconcatenate a column

    Hi,

    I need to unconcatenate a column eg _b_234_5_cdv_xyz
    (no fixed length) into 6 different columns. The underscore
    is the separator.
    What would be the most efficient way to do this.

    Samy
    Samy Guest

  2. #2

    Default Re: How to unconcatenate a column

    There is no easy way to do it with T-SQL. Take a look at the fn_Split()
    user-defined function. The article can be found at:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsqlmag01/html/TreatYourself.asp

    I've used this function in some of my projects and it has saved me a lot of
    time.

    Hope that helps.

    Mario

    "Samy" <com> wrote in message
    news:041101c35613$e07c0f60$gbl... 


    Mario Guest

  3. #3

    Default Re: How to unconcatenate a column

    This is very easy to do with the RAC utility for S2k.
    No coding necessary and there any many options.
    Check out the online docs:
    http://www.rac4sql.net/onlinehelp.asp
    See: Working with Character Strings
    Splitting Strings

    RAC v2.2 and QALite.
    www.rac4sql.net


    Groucho Guest

  4. #4

    Default Re: How to unconcatenate a column

    Assuming your strings are ALWAYS in the format you gave, there is the
    extraordinarily ugly and awkward:

    declare dlim1 int
    declare dlim2 int
    declare dlim3 int
    declare dlim4 int
    declare dlim5 int
    declare str char(50)

    set str = '_b_234_5_cdv_xyz'

    set dlim1 = charindex('_',str)
    set dlim2 = charindex('_',str,charindex('_',str)+1)
    set dlim3 = charindex('_',str,charindex('_',str,charindex('_ ',str)+1)+1)
    set dlim4 =
    charindex('_',str,charindex('_',str,charindex('_ ',str,charindex('_',str)
    +1)+1)+1)
    set dlim5 =
    charindex('_',str,charindex('_',str,charindex('_ ',str,charindex('_',str,
    charindex('_',str)+1)+1)+1)+1)

    select substring(str,1,dlim1-1) as column1,
    substring(str,dlim1+1,(dlim2-dlim1)-1) as column2,
    substring(str,dlim2+1,(dlim3-dlim2)-1) as column3,
    substring(str,dlim3+1,(dlim4-dlim3)-1) as column4,
    substring(str,dlim4+1,(dlim5-dlim4)-1) as column5,
    substring(str,dlim5+1,(len(str)-1)) as column6


    You could do it as just a select by substituting the functions used above
    back into the variables. But like the others said, not an easy thing.

    "Samy" <com> wrote in message
    news:041101c35613$e07c0f60$gbl... 


    Bob Guest

Similar Threads

  1. Column chart need column to exceed axis maximum value
    By zanedev in forum Macromedia Flex General Discussion
    Replies: 2
    Last Post: May 8th, 04:26 PM
  2. Sortable column on DataGrid -- column header not displaying
    By Teej in forum ASP.NET Data Grid Control
    Replies: 2
    Last Post: August 15th, 06:23 PM
  3. how do I unconcatenate a string
    By K-Parker in forum Macromedia Flash
    Replies: 1
    Last Post: December 11th, 03:11 AM
  4. Thanks and another quick Q, how to unconcatenate...
    By Lonewolf in forum PERL Beginners
    Replies: 1
    Last Post: September 4th, 07:36 PM
  5. Replies: 0
    Last Post: July 7th, 08:32 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139