0% found this document useful (0 votes)
4 views4 pages

SQL (Simple Query Language) Programs: Program 1: Using UPPER and LOWER Functions

The document contains SQL programs demonstrating various functions such as UPPER(), LOWER(), DATEDIFF(), DATE_ADD(), SUBSTRING(), and date extraction functions (YEAR, MONTH, DAY). It includes the creation of an Employees table, insertion of sample data, and queries that showcase how to manipulate and retrieve employee information. The outputs for each program illustrate the results of the executed queries.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

SQL (Simple Query Language) Programs: Program 1: Using UPPER and LOWER Functions

The document contains SQL programs demonstrating various functions such as UPPER(), LOWER(), DATEDIFF(), DATE_ADD(), SUBSTRING(), and date extraction functions (YEAR, MONTH, DAY). It includes the creation of an Employees table, insertion of sample data, and queries that showcase how to manipulate and retrieve employee information. The outputs for each program illustrate the results of the executed queries.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SQL (SIMPLE QUERY LANGUAGE) PROGRAMS

Program 1: Using UPPER() and LOWER() Functions


-- Create a table
CREATE TABLE Employees (
EmpID INT,
EmpName VARCHAR(50),
Department VARCHAR(30) );

-- Insert sample data


INSERT INTO Employees VALUES
(1, 'Amit Sharma', 'Sales'),
(2, 'Neha Verma', 'Marketing'),
(3, 'Rohit Mehra', 'Finance');

-- Convert employee names to UPPERCASE and lowercase


SELECT EmpName, UPPER(EmpName) AS UpperName,
LOWER(EmpName) AS LowerName
FROM Employees;

The Output:
EmpName UpperName LowerName
Amit sharma AMIT SHARMA amit sharma
Neha Verma NEHA VERMA neha verma
Rohit Mehra ROHIT MEHRA rohit mehra
Program 2: DATEDIFF()
SELECT Name,
DATEDIFF(CURRENT_DATE, HireDate) AS Days_Worked
FROM Employees;

The Output:
Name | Days_Worked
---------------------
Amit | 2075
Neha | 2380
Rohit | 1530
Priya | 2515
Karan | 840
(values depend on today’s date)

PROGRAM 3: DATE _ ADD() / DATEADD()


SELECT Name,
HireDate,
DATE_ADD(HireDate, INTERVAL 1 YEAR) AS
Next_Anniversary
FROM Employees;

The Output:
Name | HireDate | Next_Anniversary
---------------------------------------------------
Amit | 2020-01-15 | 2021-01-15
Neha | 2019-03-22 | 2020-03-22
Rohit | 2021-07-10 | 2022-07-10
Priya | 2018-11-01 | 2019-11-01
Karan | 2022-05-30 | 2023-05-30

Program 3: SUBSTRING() Function


SELECT Name, SUBSTRING(Name, 1, 3) AS Short_Name
FROM Employees;

The Output:
Name | Short_Name
--------------------
Amit | Ami
Neha | Neh
Rohit | Roh
Priya | Pri
Karan | Kar

Program 4: YEAR(), MONTH(), DAY()


SELECT Name,
YEAR(HireDate) AS Hire_Year,
MONTH(HireDate) AS Hire_Month,
DAY(HireDate) AS Hire_Day
FROM Employees;
The Output:
Name | Hire_Year | Hire_Month | Hire_Day
-------------------------------------------------------
Amit | 2020 | 1 | 15
Neha | 2019 | 3 | 22
Rohit | 2021 | 7 | 10
Priya | 2018 | 11 |1
Karan | 2022 | 5 | 30

Program 5: GROUP BY with SUM()


SELECT Department, SUM(Salary) AS Total_Salary
FROM Employees
GROUP BY Department;

The Output:
Department | Total_Salary
----------------------------------------
HR | 98000
IT | 135000
Finance | 55000

You might also like