Professional Documents
Culture Documents
SQL Functions: Objective
SQL Functions: Objective
LAB # 9
SQL FUNCTIONS
OBJECTIVE
• Aggregate Functions in SQL Server
• DateTime Function in SQL Server
• String Functions in SQL Server
LAB TASK:
Creating Database:
create table Items_Ordered2(
customer_id int not null,
order_date DATE,
item varchar (200),
quantity int not null,
price int not null
)
Barira Naveed
2020F-BSE-135
SWE-209L- DATABASE MANAGEMENT SYSTEM SSUET/QR/114
Barira Naveed
2020F-BSE-135
SWE-209L- DATABASE MANAGEMENT SYSTEM SSUET/QR/114
2. Select the average price of all of the items ordered that were purchased in the month of
Dec.
QUERY:
SELECT AVG(price) AS Average_Price FROM Items_Ordered2;
4. For all of the tents that were ordered in the items_ordered table, what is the price of the
lowest tent? Hint: Your query should return the price only.
QUERY:
Barira Naveed
2020F-BSE-135
SWE-209L- DATABASE MANAGEMENT SYSTEM SSUET/QR/114
LAB # 10
USER DEFINED FUNTIONS
OBJECTIVE:
Creating and Running User Defined Functions
LAB TASK:
Barira Naveed
2020F-BSE-135
SWE-209L- DATABASE MANAGEMENT SYSTEM SSUET/QR/114
QUERY:
Barira Naveed
2020F-BSE-135
SWE-209L- DATABASE MANAGEMENT SYSTEM SSUET/QR/114
BEGIN
RETURN LEN(@first) + LEN(@second)
END
GO
SELECT dbo.fnLetterCount('Wise','Owl')
AS 'Number of letters'
SELECT
e.EventName,
e.EventDetails,
e.EventDate,
dbo.fnLetterCount(e.EventName,e.EventDetails)
AS 'Total letters'
FROM tblEvent AS e
ORDER BY
'Total letters' ASC
Barira Naveed
2020F-BSE-135