CHARINDEX function is used to get starting position of specified expression in a string.
Syntax of CHARINDEX function :-
CHARINDEX(expression1,(expression2[,Start_Location])
expression1 is a sequence of character to be found in expression2. It is of short character datatype.
expression2 is a string in which expression1 to be search. It is of character string datatype.
Start_Location is position to start searching expression1 in expression2 .It is an optional field. If you will provide anything then it start search from position 0.
Examples:-
Example1:-
DECLARE @cust varchar(300),@pos int
set @cust='a,b,c,d'
Select CHARINDEX(',',@cust,1)
Output:-
2
Example2:-
Select CHARINDEX('am','Example-syntax-Example',1)
Output:-
3
Syntax of CHARINDEX function :-
CHARINDEX(expression1,(expression2[,Start_Location])
expression1 is a sequence of character to be found in expression2. It is of short character datatype.
expression2 is a string in which expression1 to be search. It is of character string datatype.
Start_Location is position to start searching expression1 in expression2 .It is an optional field. If you will provide anything then it start search from position 0.
Examples:-
Example1:-
DECLARE @cust varchar(300),@pos int
set @cust='a,b,c,d'
Select CHARINDEX(',',@cust,1)
Output:-
2
Example2:-
Select CHARINDEX('am','Example-syntax-Example',1)
Output:-
3
No comments:
Post a Comment
Note: only a member of this blog may post a comment.