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:
In previous articles I explained SQL Query to get particular part of string, SQL Query to replace part of string, kill all active database connections in SQL Server, SQL Query to read xml file, SQL Query to get month wise, year wise data and many articles relating to SQL Server, jQuery, JavaScript. Now I will explain how to check if string contains specific word in SQL Server.
In previous articles I explained SQL Query to get particular part of string, SQL Query to replace part of string, kill all active database connections in SQL Server, SQL Query to read xml file, SQL Query to get month wise, year wise data and many articles relating to SQL Server, jQuery, JavaScript. Now I will explain how to check if string contains specific word in SQL Server.
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 to
Aspdotnet-Suresh.com'
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 to
Aspdotnet-Suresh.com'
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
---------------------------------------
(1 row(s) affected)
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
2 comments :
why you write trivial articles?
you want to win the presence in idiotic google and create more garbage to it?
So the second query gives same result as first query????????????
Note: Only a member of this blog may post a comment.