-
Notifications
You must be signed in to change notification settings - Fork 0
/
TTCSDL_tu.sql
123 lines (111 loc) · 2.36 KB
/
TTCSDL_tu.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use [Quản lý trung tâm học thêm]
select * from LOPHOC
-- Search LH
-- Ma lop --
create procedure searchMaLop @malop char(10)
as
begin
select MaLH, TenLH, MaMH, MaGV, MaMHP
from LOPHOC
where MaLH = @malop
end
go
exec searchMaLop 'LH0002'
-- Ten lop --
create procedure searchTenLop @tenlop char(10)
as
begin
select MaLH, TenLH, MaMH, MaGV, MaMHP
from LOPHOC
where TenLH = @tenlop
end
go
exec searchTenLop N'Toán 10A1'
go
-- -----------------
alter procedure ThemMoiLH
@MaLH char(6),
@TenLH nvarchar(20),
@MaMH char(6),
@MaGV char(6),
@MaMHP char(6)
as
begin
insert into LOPHOC
(
MaLH, TenLH, MaMH, MaGV, MaMHP
)values(
@MaLH,
@TenLH,
@MaMH,
@MaGV,
@MaMHP
);
if @@ROWCOUNT > 0 begin return 1 end
else begin return 0 end;
end
go
create procedure UpdateLH
@TenLH nvarchar(20),
@MaMH char(6),
@MaGV char(6),
@MaMHP char(6)
as
begin
update LOPHOC
set
TenLH = @TenLH,
MaMH = @MaMH,
MaGV = @MaGV,
MaMHP = @MaMHP
where MaLH = @MaLH;
if @@ROWCOUNT > 0 begin return 1 end
else begin return 0 end;
end
go
create FUNCTION XemBuoiHoc(@MaHV char(10))
RETURNS TABLE
AS
RETURN (
SELECT bh.MaBH, bh.MaLH, dd.CoTrenLop, bh.ThoiGian
FROM HOCVIEN hv, DIEMDANH dd, BUOIHOC bh
WHERE hv.MaHV = dd.MaHV and bh.MaBH = dd.MaBH and hv.MaHV = @MaHV
and bh.ThoiGian BETWEEN '2020-10-01 00:00:00' AND '2020-11-01 00:00:00'
)
go
SELECT * FROM dbo.XemBuoiHoc('HV0001')
go
create FUNCTION TESTXemBuoiHoc( @malop char(10), @start varchar(50), @end varchar(50))
RETURNS TABLE
AS
RETURN (
SELECT hv.HoTen, bh.MaBH, bh.MaLH, dd.CoTrenLop, bh.ThoiGian
FROM HOCVIEN hv, DIEMDANH dd, BUOIHOC bh
WHERE hv.MaHV = dd.MaHV and bh.MaBH = dd.MaBH and bh.MaLH = @malop
and bh.ThoiGian BETWEEN @start AND @end
)
go
create FUNCTION [dbo].[TESTXemBuoiHoc2](@name nvarchar(50), @malop char(10), @start varchar(50), @end varchar(50))
RETURNS TABLE
AS
RETURN (
SELECT hv.MaHV, hv.HoTen, bh.MaBH, bh.MaLH, dd.CoTrenLop, bh.ThoiGian
FROM HOCVIEN hv, DIEMDANH dd, BUOIHOC bh
WHERE hv.MaHV = dd.MaHV and bh.MaBH = dd.MaBH and bh.MaLH = @malop and hv.HoTen = @name
and bh.ThoiGian BETWEEN @start AND @end
)
go
create procedure [dbo].[UpdateDD]
@MaBH char(10),
@MaHV char(6),
@CoTrenLop bit
as
begin
update DIEMDANH
set
CoTrenLop = @CoTrenLop
where MaBH = @MaBH and MaHV = @MaHV;
if @@ROWCOUNT > 0 begin return 1 end
else begin return 0 end;
end
go