Substring functions: LEFT and RIGHT in SQL Server 2012

Sometimes instead of use substring function You may use LEFT or RIGHT function.

In which situation using these functions?

If You want to get several chars from string beginning start from left side of string You may use LEFT function. This function get 2 parameters. One of them is string expression and another is number of chars to get. Function get string in varchar or nvarchar datatype and int or bigint value for number of chars. It returns varchar or nvarchar substring. Look at this example:

SELECT LEFT('abracadabraS',1) as mysubstring;

zz1
If You want to get several chars from string beginning start from right side of string You may use RIGHT function. This function get 2 parameters. One of them is string expression and another is number of chars to get. It is similar to LEFT function. Look at this example:

SELECT RIGHT('abracadabraS',1) as mysubstring;

If the number of chars will be given bigger than real, the all string will be return.

SELECT LEFT('abracadabraS',100) as mysubstring;

zz3

SELECT RIGHT('abracadabraS',100) as mysubstring;

zz4