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 SQL CHARINDEX function
Check following SQL statement for charindex function syntax
Check following SQL statement for charindex function syntax
CHARINDEX ( StringToFind ,OverAllStringToSearch [ , start_location ] ) |
Example 1:
Check following example for charindex function SQL Server
DECLARE @str VARCHAR(250)
SET @str='Welcome to kansiris
SELECT CHARINDEX('Aspdotnet',@str)
|
Output
Once we run above query we will get output like as shown below
---------------------------------------
(1 row(s) affected)
|
Example 2:
Another example for charindex function SQL Server
DECLARE @str VARCHAR(250)
SET @str='Welcome to kansiris
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)
|


0 comments:
Post a Comment
Note: only a member of this blog may post a comment.