Export (0) Print
Expand All

PATINDEX

SQL Server 2000

Returns the starting position of the first occurrence of a pattern in a specified expression, or zeros if the pattern is not found, on all valid text and character data types.

Syntax
PATINDEX ( '%pattern%' , expression ) 
Arguments
pattern
Is a literal string. Wildcard characters can be used; however, the % character must precede and follow pattern (except when searching for first or last characters). pattern is an expression of types that can be implicitly converted to nchar, nvarchar, or ntext.
expression
Is an expression, usually a column that is searched to find the specified pattern. expression can be nchar, nvarchar, or ntext.
Return Types

int

Examples

The following example searches the list of products that have the word Anton in their name.

SELECT ProductName, PATINDEX('%Anton%', ProductName)
FROM Products

Show:
© 2015 Microsoft