Both functions take two arguments. With PATINDEX, you must include percent signs before and after the pattern, unless you are looking for the pattern as the first (omit the first %) or last (omit the last %) characters in a column. For CHARINDEX, the pattern cannot include wildcard characters. The second argument is a character expression, usually a column name, in which Adaptive Server searches for the specified pattern.
Example of CHARINDEX:
Examples of PATINDEX:
Summary:
PATINDEX is CHARINDEX + WildCard Search. Use either of them depending your need
USE AdventureWorks;GOSELECT CHARINDEX('ensure', DocumentSummary)FROM Production.DocumentWHERE DocumentID = 3;GOExamples of PATINDEX:
USE AdventureWorks;GOSELECT PATINDEX('%ensure%',DocumentSummary)FROM Production.DocumentWHERE DocumentID = 3;GOSummary:
PATINDEX is CHARINDEX + WildCard Search. Use either of them depending your need
No comments:
Post a Comment