Important Function About SQL SUBSTRING Function

  • The SUBSTRING() function extracts a substring from a string, starting at a specified position and with an optional length.
  • It can be used with literal strings or columns in a table.
  • The LEFT() and RIGHT() functions are also implementation of SUBSTRING() Function.
  • Using SUBSTRING() in the WHERE clause negatively impacts the query performance, as the function will be executed for each row.

SQL Server SUBSTRING() Function

SUBSTRING function in SQL Server is used to extract a substring from a string, starting at a specified position and with an optional length.

It is very useful when you need to extract a specific portion of a string for further processing or analysis.

SQL SUBSTRING function also works in Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse.

Similar Reads

Syntax

The SQL SUBSTRING function syntax is:...

SQL Server SUBSTRING() Function Example

Let’s look at some examples of the SUBSTRING() function in SQL and understand how to use it in SQL server....

Rules for Using SUBSTRING() Function in SQL

All three arguments are required in the SQL substring() function. If the starting position exceeds the maximum number of characters in the expression the SQL Server substring() function returns nothing. The total length can exceed the maximum character length of the original string. In this case, the resulting substring is the entire string from the expression start position to the expression end character....

SUBSTRING() Function with Literal Strings

Using SQL SUBSTRING function with literal strings is very easy, just put the desired values in the syntax....

SUBSTRING() Function With Table Columns

To use the SUBSTRING() function with table columns we will first create a table “Player_Details“, which has three columns: PlayerId, PlayerName, and City. Since the PlayerId column is designated as the primary key, each row in the table will have a different PlayerId as its identifier....

Using  SUBSTRING on a Nested Queries

Assuming you want to use the SUBSTRING function on a nested query within the player_Details table, you could use the following SQL code...

Important Function About SQL SUBSTRING Function

The SUBSTRING() function extracts a substring from a string, starting at a specified position and with an optional length. It can be used with literal strings or columns in a table. The LEFT() and RIGHT() functions are also implementation of SUBSTRING() Function. Using SUBSTRING() in the WHERE clause negatively impacts the query performance, as the function will be executed for each row....

Contact Us