Pages

Friday, 31 May 2013

How To Make SQL Server Check if String Contains Specific Word / String with CHARINDEX Function in C# Asp.Net

How To Make SQL Server Check if String Contains Specific Word / String with CHARINDEX Function in C# Asp.Net


CHARINDEX Function

This function is used to search for specific word or substring in overall string and returns its starting position of match. In case if no word found then it will return 0 (zero).


CHARINDEX ( StringToFind ,OverAllStringToSearch [ , start_location ] )

Example 1:


DECLARE @str VARCHAR(250)
SET @str='Welcome to fantasyaspnet.blogspot.in'
SELECT CHARINDEX('fantasyaspnet.blogspot.in',@str)

Output:

---------------------------------------
12
(1 row(s) affected)

No comments:

Post a Comment