且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在两个已知字符串之间选择一个字符串的 SQL 查询

更新时间:2023-02-22 12:04:10

问题是子字符串参数的第二部分包含第一个索引.您需要从第二个索引中减去第一个索引才能完成这项工作.

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