Retrieve the position of a pattern within a string.
SELECT PATINDEX(‘%schools%’, ‘W3Schools.com’); |
The PATINDEX() function returns the starting position of a pattern within a string, and returns 0 if the pattern is not found.
Note: The search conducted by PATINDEX() is case-insensitive, and the first position in the string is considered 1.
PATINDEX(%pattern%, string) |
Parameter |
Description |
%pattern% |
Required: The pattern to search for, enclosed in ‘%’ symbols. Other supported wildcards include:
|
string |
Required: The string in which the pattern will be searched. |
Works in: |
SQL Server (since 2008), Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse |
Retrieve the position of a pattern within a string.
SELECT PATINDEX(‘%s%com%’, ‘W3Schools.com’); |
Retrieve the position of a pattern within a string.
SELECT PATINDEX(‘%[ol]%’, ‘W3Schools.com’); |
Retrieve the position of a pattern within a string.
SELECT PATINDEX(‘%[z]%’, ‘W3Schools.com’); |