1 Attachment(s)
Splitting up one string into three columns
I'm trying to split a hyphen-delimited string into three columns in a view. I've been using substring and len to split up the string, but it is getting very complicated (and isn't working in all cases). I've used a SPLIT function in vbscript - does t-sql have anything similar? I've attached a spreadsheet that shows what I am looking for. Maybe someone can guide me in the right direction?
Thanks.
Write a user defined function
Hi,
I think this is a classic requirement for a user defined function. Write a function similar to the split in vbscript. May be with an additional parameter to give u the correct element from the splitted string. For eg
udf_split(string_to_be_split,element_index)
this function can return the correct value.
Say u have a string "ABC-DEF-HIJ" and u want to get DEF. The element_index can then be 2. This way u can split a string of unlimited number of elements and retrieve the correct element to insert into ur table!
Let me know if this works
Ketan