I have a varchar
field in SQL Server 2008 like
colName_vch = 'field1;field2;field3;field4;field5;field6;field7'
I want the value of field4.
Now one long way is to do use RIGHT
,CHARINDEX
for ;
and SUBSTRING
in recursion, but that becomes very complex and increases query time.
Is there any other quick/less complex way for achieving this?
I know this is a bad DB design, but I am stuck with this for a while now.
Any help is appreciated!!
I'm not sure if i've really understood your question, but here is my guess:
You could write a custom
Split
function which splits by a delimiter(in this case;
). Then you can useROW_NUMBER
to get the desired part with a given index(4 here).For example:
Here a DEMO on sql-fiddle.
This is my split-function: