|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
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. thanks Rick |
|
#2
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Splitting out character strings |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|