Skip to content
Advertisement

How to split string with delimiter and get the first value

I have the following query where I have a table which is storing from information with a delimiter

SQL version – Microsoft SQL Azure (RTM) – 12.0.2000.8

Getting the following results

enter image description here

Where I need the results to be

enter image description here

Advertisement

Answer

If you only interested in the first value, you don’t need to use STRING_SPLIT(). You can simply use charindex() to find the first delimiter and use left() to extract it


Edit : if you always wanted the nth value, you can do a cascade charindex(). Provided that the n is not too huge. Else use the function that I provided in the comment.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement