SQL string occurrences

Function

CREATE FUNCTION [dbo].[StringOccurrence]( @StringInput VARCHAR(8000), @StringSearch VARCHAR(100) )RETURNS INTBEGIN    RETURN (LEN(@StringInput) -             LEN(REPLACE(@StringInput, @StringSearch, ''))) /            LEN(@StringSearch)ENDGO

Usage

SELECT * FROM CTE_EmailsWHERE  dbo.StringOccurrence(Email, '@') = 1

 

Leave a Reply

Your email address will not be published. Required fields are marked *