LEFT function in SQL Server

The article will learn and show you how to use the LEFT function in SQL Server to extract some characters from the left side of a given string.

Describe

The LEFT function in SQL Server allows you to extract a substring from a large string, starting from the leftmost character.

Syntax

To use LEFT function in SQL Server, we use the following syntax:

 LEFT(chuoi, so_ky_tu) 

Parameters :

  1. chuoi: can be a string, variable or column that you want to extract.
  2. so_ky_tu: a positive integer that specifies the number of characters that will be returned from the cycle, starting from the leftmost character.

Note :

  1. If so_ky_tu exceeds the length of the string, LEFT function returns the original string.
  2. The LEFT function can be used in later versions of SQL Server: SQL Server 2017, SQL Server 2016, SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, and SQL Server 2005.

For example

Take a look and explore some examples of LEFT functions in SQL Server.

 SELECT LEFT('TipsMake.com', 12); 
Result: 'Quantrimang.'

SELECT LEFT('TipsMake.com', 4);
Result: 'Quan'

SELECT LEFT('Quan Tri Mang', 9);
Result: 'Quan Tri '

SELECT LEFT('Quan Tri Mang', 100);
Result: 'Quan Tri Mang '

Previous article: DATALENGTH function in SQL Server

Next article: LEN function in SQL Server

4.3 ★ | 3 Vote

May be interested

  • DATEPART function in SQL ServerDATEPART function in SQL Server
    the datepart function in sql server returns a time value of the input argument, which can be day, month, year, quarter, hour, minute, second, millisecond ... the return value is an integer type (int)
  • How to combine Vlookup function with Left functionHow to combine Vlookup function with Left function
    when combining the vlookup function with the left function, we will easily separate the values ​​to find the right information we need.
  • DATENAME function in SQL ServerDATENAME function in SQL Server
    the datename function in sql server returns a time value of the input argument, which can be day, month, year, quarter, hour, minute, second, millisecond ... the return value is a string type (ascii)
  • Do you know the structure and usage of the LEFT function in Excel?Do you know the structure and usage of the LEFT function in Excel?
    this article guides you in detail about the structure and usage of common and effective left function in excel
  • ROUND function in SQL ServerROUND function in SQL Server
    the article will give you detailed instructions on how to use the sql server round () function with the syntax and specific examples to make it easier to visualize and capture the function better.
  • CEILING function in SQL ServerCEILING function in SQL Server
    the ceiling function in sql server returns the smallest integer value greater than or equal to the transmitted numeric expression.
  • RIGHT function in SQL ServerRIGHT function in SQL Server
    the article will explore and guide you how to use the right function in sql server to extract some characters from the right side of a given string.
  • FLOOR function in SQL ServerFLOOR function in SQL Server
    the floor function in sql server returns the largest integer value but less than or equal to the transmitted numeric expression.
  • MONTH function in SQL ServerMONTH function in SQL Server
    this article will show you in detail how to use the datetime month () processing function in sql server with specific syntax and examples to better visualize and capture functions.
  • DATEDIFF function in SQL ServerDATEDIFF function in SQL Server
    this article will show you in detail how to use sql server's datetime datediff () function with syntax and specific examples to make it easier to visualize and capture functions.