What is PATINDEX in SQL Server?


It returns the starting position of the first occurrence of a pattern in a specified String.
If the pattern is not found then it will return zero. It applies on all valid text and character data types.
Syntax : PATINDEX ( ‘%pattern%’ , String_Exp)
Example :

DECLARE @Pattern VARCHAR(50), @String_Exp VARCHAR(50)
Set @Pattern='%[0-9]%'
Set @String_Exp='Hi123t4e5s6h'
Select PATINDEX(@Pattern, @String_Exp)


Result : 3
In this example first occurrence of integer value is at position 3.