CHARINDEX函数用于在字符串中查找指定子字符串的位置。
语法:CHARINDEX(substring, string, start_index)
参数说明:
substring: 要查找的子字符串string: 要在其中搜索的字符串start_index: 可选参数,指定开始搜索的位置,默认为1示例:
在字符串’Hello world’中查找子字符串’world’的位置:SELECT CHARINDEX('world', 'Hello world');结果为:7
在字符串’Hello world, Hello universe’中查找子字符串’Hello’的位置:SELECT CHARINDEX('Hello', 'Hello world, Hello universe');结果为:1
在字符串’abcdefg’中从第3个位置开始查找子字符串’cd’的位置:SELECT CHARINDEX('cd', 'abcdefg', 3);结果为:3


