technology | February 16, 2026

What is the difference between Charindex and Patindex?

What is the difference between Charindex and Patindex?

CHARINDEX and PATINDEX are used to get starting position of a pattern. The functional difference is that the PATINDEX can use wild characters in the pattern being searched whereas CHARINDEX can’t. The two queries search for CREATE pattern in sys. sql_modules.

What is SQL Patindex?

The PATINDEX() function returns the position of a pattern in a string. If the pattern is not found, this function returns 0.

How do I get the last 3 characters of a string in SQL?

SQL Server RIGHT() Function

  1. Extract 3 characters from a string (starting from right): SELECT RIGHT(‘SQL Tutorial’, 3) AS ExtractString;
  2. Extract 5 characters from the text in the “CustomerName” column (starting from right):
  3. Extract 100 characters from a string (starting from right):

What is Charindex?

The SQL CHARINDEX function is used to return the position of the specified substring in a string. This is the start location in the string which is an int type. If no match is found in the given string, the CHARINDEX returns 0.

What do you understand by wildcard characters?

In software, a wildcard character is a kind of placeholder represented by a single character, such as an asterisk ( * ), which can be interpreted as a number of literal characters or an empty string. It is often used in file searches so the full name need not be typed.

Is Patindex faster than like?

I keep seeing the same suggestion on various “tips and tricks” websites: For situations in which you might want to use LIKE in the WHERE clause, but for which indexes cannot be used, PATINDEX will perform faster.

Is Charindex case sensitive?

CHARINDEX is case-sensitive. Use one of the case-conversion functions to locate both uppercase and lowercase instances of a letter or character string.

How does Charindex work in SQL?

SQL Server CHARINDEX() function searches for a substring inside a string starting from a specified location. It returns the position of the substring found in the searched string, or zero if the substring is not found. The starting position returned is 1-based, not 0-based.

How do I get last 5 characters of a string in SQL?

To get the first n characters of string with MySQL, use LEFT(). To get the last n char of string, the RIGHT() method is used in MySQL.

What is NVL null function in SQL?

NVL (expr1, expr2) : In SQL, NVL () converts a null value to an actual value. NVL2 (expr1, expr2, expr3) : The NVL2 function examines the first expression. DECODE () : Facilitates conditional inquiries by doing the work of a CASE or IF-THEN-ELSE statement.

What are the functions of SQL?

SQL has a number of functions to assist you in your database programming. Functions are a self contained script/program built for a specific purpose. Generally, the value returned by a function will depend on the context in which it is being used. Often, a SQL function will be used within a query and this is what provides it with it’s context.

What is a string function in SQL?

Sql string function is a built-in string function. It perform an operation on a string input value and return a string or numeric value.