A SQL Query to select a string between two known strings

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'))

Leave a Comment