Use of Charindex Function in SQL with an example
In this article We will discuss How to use Charindex Function in SQL Server. It is utilized to hunt down particular keywords or sub-string in string and gives back to its beginning position of the match string. In the event that if no word found, then it will return 0.
Syntax of Charindex function
Output of above query is 31
Above query search will start from 8th position of string and we will get output like as shown below
Output of above query is 31
Syntax of Charindex function
CHARINDEX ( SearchString ,OverAllString , [start_location ] )
- SearchString: Replace SearchString with search text
- OverAllString: Replace OverAllString with given full text.
Example:
Read following example carefully for charindex function
DECLARE @str NVARCHAR(MAX) SET @str='Learn how to use Charindex in aspbucket.com' SELECT CHARINDEX('aspbucket',@str)
DECLARE @str NVARCHAR(MAX) SET @str='Learn how to use Charindex in aspbucket.com' SELECT CHARINDEX('aspbucket',@str,8)
Output of above query is 31
0 comments :
Post a Comment