I have this long string in one of the columns of the table. I want to get only specific information:- My Table structure:-
Col1 = '123'
Col2 = 'AAAAA'
Col3 = 'Clent ID = 4356hy|Client Name = B B BOB|Client Phone = 667-444-2626|Client Fax = 666-666-0151|Info = INF8888877 -MAC333330554/444400800'
My select statement is:-
Select col1, col2, col3 from Table01
But in Col3 I just need 'Client Name's value which is 'B B BOB'.
In Col3 -
Column delimiter is '|' pipe char (eg. 'Client ID = 4356hy')
Key Value delimiter is ' = ' equal to sign with one white space (leading and trailing).
Please help.
You need a split function:
With your split function, you would then use Cross Apply to get the data:
You simply need to do a SUBSTR on the string in col3....
And yes, that is a bad DB design for the reasons stated in the original issue
For your specific data, you can use
EDIT - charindex vs patindex
Test
Timings
Conclusion
The timings for CharIndex and PatIndex for 700k calls are within 3.5% of each other, so I don't think it would matter whichever is used. I use them interchangeably when both can work.
It is terrible, but you can try to use
This code is probably not 100% right though. need to be adjusted