Monday 23 February 2015

The SUBSTR Function in SQL

The SUBSTR function returns specified characters from character value, starting from P, L characters long.  The following statement fetches records of employees who have ‘lex’ (three characters) in their names starting from second position.

NOTE
In Microsoft Access use MID() function. In Microsoft SQL Server, MySQL, and MariaDB you have to use SUBSTRING().


    Syntax :
SUBSTR (character, P,L)

    SQL Statement :
SELECT    first_name, last_name, salary
FROM      employees
WHERE    substr(first_name,2,3)='lex';   

    Output :











No comments:

Post a Comment