-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctions.sql
56 lines (55 loc) · 1.18 KB
/
Functions.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
-- D--
--1
-- Function to calculate the average score of a topic
GF
CREATE FUNCTION DTB_DT (@MSDT CHAR (6)) RETURNS FLOAT
AS
BEGIN
DECLARE @DTB FLOAT
SELECT @DTB = AVG(DIEM)
FROM (SELECT * FROM GV_HDDT UNION
SELECT * FROM GV_PBDT UNION
SELECT * FROM GV_UVDT) AS DIEMTONGHOP
WHERE MSDT = @MSDT
IF @DTB IS NULL
SET @DTB = 0
RETURN @DTB
END
GO
-- THUC THI
SELECT DBO.DTB_DT ('97002') AS KQ
-- 2
-- Function returns the results of the topic according to the entered MSDT
GO
CREATE FUNCTION KQ_DT (@MSDT CHAR (6)) RETURNS NVARCHAR(50)
AS
BEGIN
DECLARE @DTB FLOAT
DECLARE @KQ NVARCHAR(50)
SELECT @DTB = AVG(DIEM)
FROM (SELECT * FROM GV_HDDT UNION
SELECT * FROM GV_PBDT UNION
SELECT * FROM GV_UVDT) AS DIEMTONGHOP
WHERE MSDT = @MSDT
IF @DTB >=5
SET @KQ='DAT'
ELSE SET @KQ ='KHONGDAT'
RETURN @KQ
END
GO
-- THUC THI
SELECT DBO.KQ_DT('97002') AS KQ
-- 3
-- Returns the student code and full name of the students conducting the project with the corresponding entered MSDT
GO
CREATE FUNCTION SV_TH_DT (@MSDT CHAR (6)) RETURNS TABLE
AS
RETURN(
SELECT MSSV,TENSV
FROM SINHVIEN
WHERE MSSV IN
(SELECT MSSV FROM SV_DETAI WHERE MSDT=@MSDT)
);
GO
-- THUC THI
SELECT*FROM SV_TH_DT ('97001')