PATINDEX()

PATINDEX returns the starting position of the first occurrence of a pattern in a specified expression, or zero.

Signature

PATINDEX ( '%pattern%' , expression )

Parameters

  • pattern — A character expression that contains the sequence to be found. Wildcard characters can be used; however, the % character must come before and follow *pattern* (except when you search for first or last characters). *pattern* is an expression of the character string data type category. *pattern* is limited to 8,000 characters.
  • expression — An expression, typically a column that is searched for the specified pattern. *expression* is of the character string data type category.

Examples

SELECT PATINDEX('%bo%', 'keyboard') AS position;
position
-----------
          4
SELECT PATINDEX('%ter%', 'interesting data') AS position;
3
SELECT PATINDEX('%en_ure%', 'Please ensure the door is locked!') AS position;
8

Run against SQL Server 16.0.4265.3 on 2026-09-13. This is the output we got, not the documentation’s.

Available on

  • SQL Server 2017 and later
  • Azure SQL Database
  • Azure SQL Managed Instance
  • Azure Synapse Analytics
  • Analytics Platform System (PDW)
  • Microsoft Fabric warehouse
  • Fabric SQL database

Signature and description adapted from the Microsoft SQL documentation, used under the CC BY 4.0. SQL Server and Azure are trademarks of the Microsoft group of companies. This page is not affiliated with Microsoft.