This topic contains and tries to cover following subjects
- Explanation of RIGHT and LEFT () functions in SQL
- Syntax of RIGHT and LEFT () functions in SQL
- Example to RIGHT and LEFT () functions in SQL
Articles contains and tries to provide answer to following questions and issues:
- What is RIGHT and LEFT() function..
- How to use RIGHT and LEFT() function..
- How to select a specified number of char acters from left or right of the string
Articles may require following knowledge:
- Basic query flow in SQL
- SQL Server Management Studio
- SQL Server string functions
Explanation of RIGHT and LEFT () function in SQL
RIGHT and LEFT () functions are used to return a specified number of char acters from the string . Right refers to end of the string contrary to LEFT. Lets assume that we have a varchar type data as string in a column. When we need to get last 5 char acter of text or first 2 char acter, we can use those functions to return the specified number of char acters from any side.
Syntax of RIGHT and LEFT () function in SQL
Syntax for RIGHT and LEFT () functions are as follows:
LEFT ( input string , char acter count to be selected )
RIGHT ( input string , char acter count to be selected )
Example of RIGHT and LEFT () function in SQL
To demonstrate how RIGHT and LEFT functions work, we will use them in a SELECT query to get 3 char acter from left of a provided string , and 4 char acter from right of same string .
Query is as follows: