Jim Horn
asked on
What's the difference between CHARINDEX and PATINDEX?
Hi All
Question for you: What's the difference between CHARINDEX and PATINDEX?
The difference is not clear to me.
When I run the below script it returns the same values:
Full disclosure: I'm studying for the 70-433 exam, and this is not a work-related question.
Question for you: What's the difference between CHARINDEX and PATINDEX?
The difference is not clear to me.
When I run the below script it returns the same values:
Declare @str varchar(100) = 'abcdefghigklmnopqrstuvwxyz_e'
/*
CHARINDEX
http://msdn.microsoft.com/en-us/library/ms186323.aspx
Searches an expression for another expression and returns its starting position if found.
*/
-- Select the first e in a string
SELECT CHARINDEX('ef', @str)
-- Select the first e in a string, starting at the 10th character
SELECT CHARINDEX('e', @str, 10)
/*
PATINDEX
http://msdn.microsoft.com/en-us/library/ms188395
Turns the starting position of the first occurrence of a pattern in a specified expression,
or zeros if the pattern is not found, on all valid text and character data types.
*/
SELECT PATINDEX('%efg%', @str)
They both return bigint's that are the starting values. Full disclosure: I'm studying for the 70-433 exam, and this is not a work-related question.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay. That I saw, but was wondering if it was any other difference. Now I know. Thanks.