Introduction:
Here
I will explain how to check if string contains specific word in SQL
Server using CHARINDEX function or SQL
Server check if string contains specific substring with CHARINDEX
function.
Description:
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).
Syntax
of CHARINDEX
CHARINDEX ( StringToFind ,OverAllStringToSearch [ , start_location ] )
|
Example
1:
DECLARE @str VARCHAR(250)
SET @str='Welcome '
SELECT CHARINDEX('Aspdotnet',@str)
|
Output
Once
we run above query we will get output like as shown below
---------------------------------------
(1 row(s) affected)
|
Example
2:
DECLARE @str VARCHAR(250)
SET @str='Welcome '
SELECT CHARINDEX('Aspdotnet',@str,7)
|
Output
Once
we run above query search will start from 7th position of string and
we will get output like as shown below
---------------------------------------
12
|
0 comments:
Post a Comment