Skip to main content
Scalar function
Aliases: strpos, charindex NULL string/search, or a supplied NULL start/occurrence operand, returns NULL. Omitted start and occurrence default to one.

Syntax

Scalar

Strpos form (scalar)

  • Use STRING search and value operands and an INTEGER start of at least one.

Charindex form (scalar)

  • Use STRING search and value operands and an INTEGER start of at least one.

Arguments

Scalar, charindex form

Strpos form

Returns

  • Type: BIGINT; query tools may report INTEGER
  • Possible values: One-based position or zero when absent.
  • NULL behavior: NULL string/search, or a supplied NULL start/occurrence operand, returns NULL. Omitted start and occurrence default to one.

Properties

Usage notes

  • INSTR uses haystack, needle; LOCATE uses needle, haystack.
  • STRPOS takes the text to search first, then the substring. CHARINDEX and LOCATE take the substring first, then the text to search.

Examples

Typical behavior

Alias calling form: STRPOS

Alias calling form: CHARINDEX

Limitations

  • The position is returned as BIGINT, even when query tools report INTEGER.
  • Use start and occurrence values of at least 1. Zero or negative values can fail or give unexpected results. For non-ASCII text, a start position beyond the string’s length can restart the search at the beginning.
Last modified on October 15, 2026