Search for "t" in string "Customer", and return position:
SELECT CHARINDEX('t', 'Customer') AS MatchPosition;
Try it Yourself »
The CHARINDEX() function searches for a substring in a string, and returns the position.
If the substring is not found, this function returns 0.
Note: This function performs a case-insensitive search.
CHARINDEX(
substring,
string,
start)
Parameter | Description |
---|---|
substring | Required. The substring to search for |
string | Required. The string to be searched |
start | Optional. The position where the search will start (if you do not want to start at the beginning of string). The first position in string is 1 |
Works in: | SQL Server (starting with 2008), Azure SQL Database, Azure SQL Data Warehouse, Parallel Data Warehouse |
---|
Search for "OM" in string "Customer", and return position:
SELECT CHARINDEX('OM', 'Customer') AS MatchPosition;
Try it Yourself »
Search for "mer" in string "Customer", and return position (start in position 3):
SELECT CHARINDEX('mer', 'Customer', 3) AS MatchPosition;
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!