PATINDEX Function [String]

The PATINDEX function returns a 64-bit unsigned integer containing the position of the first occurrence of the specified pattern in a LONG VARCHAR column or variable. For CHAR and VARCHAR columns, PATINDEX returns a 32-bit unsigned integer position.

Syntax

PATINDEX( ‘%pattern%’, long-varchar-column )

Parameters

Usage

  • All the positions or offsets, returned or specified, in the PATINDEX function are always character offsets and may be different from the byte offset for multibyte data.
  • If the LONG VARCHAR cell being searched contains more than one instance of the string pattern, PATINDEX returns only the position of the first instance.
  • If the column does not contain the pattern, PATINDEX returns zero (0).
  • Searching for a pattern longer than 126 bytes returns NULL.
  • Searching for a zero-length pattern returns 1.
  • If any of the arguments is NULL, the result is zero (0).
  • PATINDEX supports LONG VARCHAR variables of any size of data. Currently, a SQL variable can hold up to 2GB - 1 in length. PATINDEX does not support LONG BINARY variables or searching LONG BINARY columns.