Skip to content
Advertisement

Select text from inside a string after a keyword

I have a column in SQL Server that has a string that looks like this. I’m trying to get the value of the “some_id” which in this case would ‘12345678911’. Any help on how I could get just that numerical value. I can’t seem to get it using the Substring() and Charindex() functions.

Any help would be much appreciated.

EDIT – Heres where my attempt is currently at, and I also did not want that 28 characters hard coded. It should stop at the first double quote.

Advertisement

Answer

For your given example the following returns the required result. You just create a substring from your starting point and then find the next pair of double quotes, then substring between the starting point and the next pair of double quotes:

Which can be combined into a single statement, but you can see that duplicates code, so I find separating it out is clearer:

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