A SQL Query to select a string between two known strings

The Solution to A SQL Query to select a string between two known strings is


The problem is that the second part of your substring argument is including the first index. You need to subtract the first index from your second index to make this work.

SELECT SUBSTRING(@Text, CHARINDEX('the dog', @Text)
, CHARINDEX('immediately',@text) - CHARINDEX('the dog', @Text) + Len('immediately'))

~ Answered on 2013-08-21 16:33:32


Most Viewed Questions: