Thursday, February 28, 2013

SQL Server LEFT Function

In my previous posts, I explained CHARINDEX Function, CHAR Function, ASCII Function, Simple script to backup all SQL Server databases, Table-Valued Parameters and some other articles related to SQL Server.

Here, I am going to explain LEFT function of SQL Server.

LEFT() Function

This function is used to get the left most specified number of characters from a character expression. i.e. it reruns the specified number of characters starting from left most character of character expression.
 
Syntax- LEFT(character_expression, number_of_characters )
Arguments- 
  • character_expression : An expression containing the sequence of character.
  • number_of_characters : An integer value that specifies how many characters of the character_expression will be returned. number_of_characters should be a positive integer, If it is negative then, an error is returned.
Return Type- varchar(number_of_characters) or nvarchar(number_of_characters)

Example-
 
Declare @inputvalue as varchar(50)
set @inputvalue='Dot Net World'
Select Left(@inputvalue,6)
--Output= Dot Ne


No comments:

Post a Comment

^ Scroll to Top