SQL QueriesSQL Tips

Finding the Start Position of a String Within Another String

By 08/12/2022 October 8th, 2023 No Comments

Problem Statement :

This article explains how to find the starting index of the first occurrence of a pattern in a string or a specified expression  using PATINDEX() function in SQL server.

  • It returns zero if the pattern is not found.
  • It returns Null if either pattern or expression is NULL.

Code Snippet:

Select [Name],[GroupName], PATINDEX( ‘% and %’ ,[GroupName]) as startingStartingPoint
FROM [AdventureWorks].[HumanResources].[Department]

Code Output:

Leave a Reply