Category Archives: SQL Functions

SQL Functions

RIGHT() function in SQL Server

By | January 26, 2015

SQL Server – RIGHT () function Right():- This function returns the specified number of characters from the Right part of the given character string. Syntax:- Select RIGHT ( character_expression , integer_expression ) For example, the below query will return two characters from the last. Select RIGHT(‘Vivek’,2) Result ek Database Consultant with more than 11.5 years of… Read More »

LEFT() function in SQL Server

By | January 26, 2015

LEFT() function in SQL Server Left() Function  This function returns the specified number of characters from the left part of the given character string. Syntax Select LEFT ( character_expression , integer_expression )For example, the below query will return two characters from the beginning Select LEFT  (‘Vivek’,2) Result Vi Database Consultant with more than 11.5 years… Read More »

SQL Server – Convert() function

By | January 24, 2015

Convert () function in SQL Server Convert () function is used to convert an expression from one data type to another data typeSyntax for CONVERT function CONVERT ( data_type [ ( length ) ] , expression [ , style ] ) Convert functions is usually used with date/time data type to convert a date in different formats. Below examples will… Read More »

AVG() function in SQL Server

By | August 14, 2014

Avg():- This function is used to get the average value of a numeric column Syntax:-       SELECT AVG(column_name) FROM table_name In this article, we are going to use the following table for some examples:- CREATE TABLE [dbo]. [Employee]( [Empid] [Int] IDENTITY (1, 1) NOT NULL Primary key, [EmpNumber] [nvarchar](50) NOT NULL, [EmpFirstName] [nvarchar](150) NOT NULL,… Read More »

UPPER() function in SQL Server

By | August 14, 2014

UPPER():- This function is used to convert the value of a column to upper case.  Syntax:    SELECT UPPER(string) OR Select UPPER(Column name) from tablename For example,   SELECT UPPER(‘Vivek’) Result:    VIVEK Database Consultant with more than 11.5 years of experience in database designing & programming and DBA related activities.  Had good experience on… Read More »

LEN() function in SQL Server

By | August 14, 2014

LEN():- This function is used to get the length of the given string value.   Syntax:-     Select len (stringvalue)   For example,     Select len(‘Vivek Johari’)    Result:-    12 Database Consultant with more than 11.5 years of experience in database designing & programming and DBA related activities.  Had good experience on different databases… Read More »

LOWER() function in SQL Server

By | August 14, 2014

LOWER():- This function is used to convert the value of a column to lower case  Syntax:-  Select LOWER (string)    or    SELECT LOWER(column_name) FROM table_name For example, SELECT LOWER(‘Vivek Johari’) Result:- vivek johari Database Consultant with more than 11.5 years of experience in database designing & programming and DBA related activities.  Had good experience… Read More »

LTRIM() function in SQL Server

By | August 14, 2014

LTRIM ():- This function is used to get the string after the removal of leading blank spaces. Syntax:- LTRIM ( character_expression ) For example:- Select LTRIM  (‘  Vivek Johari’) Result:- Vivek Johari (without blank spaces on left side) Database Consultant with more than 11.5 years of experience in database designing & programming and DBA related… Read More »

Substring() function in SQL Server

By | August 14, 2014

Substring():- This function is used to return the specified number (third argument “len”) of characters from a given string(first argument) from the start position as specified as the second argument. Syntax:-    Select  SUBSTRING ( expression ,start , length ) For example,        Select  SUBSTRING ( ‘kingmaker’ ,1 , 4 ) Result     king Database… Read More »