如何获取SQL Server中的最后一个索引?

时间:2019-10-07 01:45:24

标签: sql-server

我想获取最后一个索引。

示例。

"Hello, World~! this is a sample"

我将搜索“ this”。

结果为4(此索引->'s')

1 个答案:

答案 0 :(得分:0)

以下查询应执行您想要的操作:

DECLARE @text VARCHAR(100) = '"Hello, World~! this is a sample"'
DECLARE @ser VARCHAR(50) = 'this'

SELECT LEFT(REVERSE(SUBSTRING(@text,CHARINDEX(@ser,@text),LEN(@ser))),1)