jjliu4492
asked on
How to use substring to split a string value
I have a string value, that I want to separate into 6 strings. The delimiter is _. So for this string, the six values would be: How would I go about splitting the string in SQL Server 2008?
TAMPA, FL_VASTEC__ACCESSIBILITY TRAINING_508_FIRST
TAMPA, FL
VASTEC
null
ACCESSIBILITY TRAINING
508
FIRST
TAMPA, FL_VASTEC__ACCESSIBILITY TRAINING_508_FIRST
TAMPA, FL
VASTEC
null
ACCESSIBILITY TRAINING
508
FIRST
it depends a bit what you want to do with the values ...
I also wrote an article about this kind of thing: https://www.experts-exchange.com/A_1536.html
I also wrote an article about this kind of thing: https://www.experts-exchange.com/A_1536.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am trying to split up the field, and save the split values into a new table. Can I do this without using a function, and just use substring?
>Can I do this without using a function, and just use substring?
not really. technically yes, but you will multiply the instr() and substring functions...
not really. technically yes, but you will multiply the instr() and substring functions...
ASKER
select * from dbo.fnSplit('TAMPA, FL_VASTEC__ACCESSIBILITY TRAINING_508_FIRST', '_')
Can I have it display as one row, with each field as a column?
Can I have it display as one row, with each field as a column?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
If I use fnSplit, my result set is:
How can I get a specific row value? For example, I need to insert "VASTEC" into a column in my database.
item
TAMPA, FL
VASTEC
NULL
ACCESSIBILITY TRAINING
508
FIRST
How can I get a specific row value? For example, I need to insert "VASTEC" into a column in my database.
item
TAMPA, FL
VASTEC
NULL
ACCESSIBILITY TRAINING
508
FIRST
please see my comment above.
ASKER
What is your code for dbo.ParmsToList?
it's in the article I linked above
Open in new window