1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Rep Power

    Splitting out character strings

    Help! I am working with an off-the-shelf shopping cart and now have the data in a MS SQL Server. All of our product options are loaded into one column separated with brackets like this: [Gift Wrap: Birthday] [Frame Color: Black] Each string has the option type (ie Frame Color) and then what the customer selected (ie Black). I need to be able to separate out the options for querys etc.

    I have tried to use the charindex and substring functions which gets very complicated and I can't seem to find the end bracket:

    SELECT OrderID, Substring(Options, charindex('[Gift Wrap:',Options)+11, charindex('][',Options, charindex('[Gift Wrap:',Options)+11)) AS "GiftWrap"
    FROM OrderDetails

    I was also wondering if I can somehow create new columns that can hold the parsed data.

    I sure would appreciate some help.


  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Rep Power
    what you probably need to use is the substring function with patindex. something like:

    select substring( options, patindex(%:%, options), datalength(options) - patindex(%:%, options) - 1)
    from orderdetails

    also, are you looking to create new columns in the order details table to hold the data? it might be easier to use variable tables to do this instead.

IMN logo majestic logo threadwatch logo seochat tools logo