Skip to content

Instantly share code, notes, and snippets.

@FlameWert
Created January 9, 2023 17:19
Show Gist options
  • Save FlameWert/99551b1c7ceed2ba9ad8ec420f24453a to your computer and use it in GitHub Desktop.
Save FlameWert/99551b1c7ceed2ba9ad8ec420f24453a to your computer and use it in GitHub Desktop.
Find text occurrence in SQL Server
DECLARE @tosearch VARCHAR(MAX)='In'
SELECT (DATALENGTH(@string)-DATALENGTH(REPLACE(@string,@tosearch,'')))/DATALENGTH(@tosearch)
AS OccurrenceCount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment