The CharIndex and PatIndex functions both categorized under the string function in SQL SERVER with little bit of difference.
So, this blog explore the difference between CharIndex and PatIndex function in SQL SERVER.
Similarity
Both the functions accepts two arguments to search the specified text filed in the given expression.
Both the function returns the starting position of the matching pattern given in the function.
Difference
The PatIndex function is used with the wildcard characters. You must enclosed the wildcard characters before (when searching at last) or after (when looking for first) the searching text.
But, the CharIndex function can not be used any wildcard characters with the specified searching pattern. In the CharIndex function will not work upon the wildcard characters.
Example of PatIndex
SELECT (PATINDEX('%Corner%', 'C-SharpCorner'))
Will result 8.
Example of CharIndex
SELECT (charindex('Corner', 'C-SharpCorner'))
Will also result 8.