-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPunto_02.sql
More file actions
218 lines (172 loc) · 6.38 KB
/
Copy pathPunto_02.sql
File metadata and controls
218 lines (172 loc) · 6.38 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
2. Reporte de estudiante por curso. Utilizar Cursor
- Se desea conocer de un estudiante: Los cursos que ha matriculado en la historia, los cursos que ha aprobado y reprobado,
las notas y los cursos pendientes que le faltan para concluir el plan.
- Consultar por rango de años
*/
CREATE OR ALTER PROCEDURE P_GetEstudentCourseHistory
@Ln_id_student INT,
@Lv_start_year CHAR(4) = NULL,
@Lv_end_year CHAR(4) = NULL
AS
DECLARE @Lv_status_reprobed CHAR(4) ='R';
DECLARE @Lv_status_aprobed CHAR(4) ='A';
DECLARE @Lv_status_suscription CHAR(4) ='M';
DECLARE c_status_suscriptions CURSOR FOR
Select id, title
From cat_suscriptions_status;
DECLARE @Lv_id_status CHAR(5);
DECLARE @Lv_title_status VARCHAR(50);
DECLARE @Lv_student_name VARCHAR(400);
BEGIN
IF (@Lv_start_year IS NOT NULL AND @Lv_end_year IS NOT NULL)
BEGIN
-- Si el segundo es menor se cambian
IF ( YEAR(@Lv_start_year) > YEAR(@Lv_end_year) )
BEGIN
DECLARE @Lv_elderly_year CHAR(4) = @Lv_start_year;
SET @Lv_start_year =@Lv_end_year;
SET @Lv_end_year =@Lv_elderly_year;
END;
END;
SET @Lv_student_name = dbo.F_GetCompleteNameUser(@Ln_id_student);
-- se abre el cursor c_status_suscriptions
OPEN c_status_suscriptions
FETCH c_status_suscriptions
INTO @Lv_id_status, @Lv_title_status;
PRINT CONCAT('Reporte de historial de cursos del estudiante ',@Lv_student_name, ', del año ', @Lv_start_year, ' al ', @Lv_start_year, '.' )
-- Para cursor c_status_suscriptions
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE @Ln_contador INT = 0;
PRINT '_________________________________________________________________________'
PRINT CONCAT('_________________','Cursos ', @Lv_title_status, 's(',TRIM(@Lv_id_status),')','_________________' )
DECLARE c_courses_student CURSOR FOR
SELECT
dbo.F_GetNameCourseFromCourseXCareer(dbo.F_GetCodeCourseByPeriodsCourses(PCS.id_periods_courses)) AS course_name,
score,
p.[start_date ],
p.[end_date]
--PCS.[status]
FROM periods_courses_suscriptions PCS
Right Join periods_courses PC
Right Join [periods] P
On P.id = PC.id_periods
And (
-- Si es nula alguna de los dos años no se tienen en cuenta
(@Lv_start_year is null or @Lv_end_year is null)
Or
YEAR( p.[start_date ]) between @Lv_start_year and @Lv_end_year
Or
YEAR( p.[end_date]) between @Lv_start_year and @Lv_end_year
)
ON PC.id = PCS.id_periods_courses
Where student_id = @Ln_id_student
And PCS.[status] = @Lv_id_status
Order By p.[start_date], p.[end_date];
DECLARE @Lv_course_name VARCHAR(400);
DECLARE @Ln_score VARCHAR(400);
DECLARE @Ld_start_date DATETIME;
DECLARE @Ld_end_date DATETIME;
-- se abre el cursor c_courses_student
OPEN c_courses_student
FETCH c_courses_student
INTO @Lv_course_name, @Ln_score, @Ld_start_date,@Ld_end_date;
-- Para cursor c_courses_student
WHILE @@FETCH_STATUS = 0
BEGIN
SET @Ln_contador = @Ln_contador+1;
DECLARE @Lv_fecha VARCHAR(200) ;
SET @Lv_fecha = CONCAT('[',CONVERT(VARCHAR, @Ld_start_date, 1) , ' - ', CONVERT(VARCHAR, @Ld_end_date, 1) ,']')
PRINT CONCAT(@Lv_student_name, ' - ' , @Lv_course_name ,' - ', @Ln_score ,'. ', @Lv_fecha)
FETCH c_courses_student
INTO @Lv_course_name, @Ln_score, @Ld_start_date,@Ld_end_date;
END;
CLOSE c_courses_student
DEALLOCATE c_courses_student
FETCH c_status_suscriptions
INTO @Lv_id_status, @Lv_title_status;
PRINT CONCAT('_________________','Total: ', @Ln_contador,'_________________')
PRINT ' '
PRINT ' '
PRINT ' '
SET @Ln_contador = 0;
END
CLOSE c_status_suscriptions
DEALLOCATE c_status_suscriptions
END;
EXEC P_GetEstudentCourseHistory 21, '2021', '2020';
CREATE OR ALTER PROCEDURE P_GetMissingCourses
@Ln_id_student INT
AS
DECLARE c_study_plan_suscriptions CURSOR FOR
Select id_study_plan,
SP.[title] AS plan_study_title,
SP.[description] as plan_study_description
From study_plan_suscriptions SPS
Left Join study_plan SP
On SP.id = SPS.id_study_plan
Where SPS.id_student= @Ln_id_student;
DECLARE @Lv_study_plan_code INT;
DECLARE @Lv_study_plan_title VARCHAR(200);
DECLARE @Lv_study_plan_description CHAR(400);
DECLARE @Lv_student_name VARCHAR(400);
BEGIN
SET @Lv_student_name = dbo.F_GetCompleteNameUser(@Ln_id_student);
OPEN c_study_plan_suscriptions
FETCH c_study_plan_suscriptions
INTO @Lv_study_plan_code, @Lv_study_plan_title, @Lv_study_plan_description;
PRINT CONCAT('Cursos pendientes de ',@Lv_student_name)
-- Para cursor carrer_suscriptions
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT CONCAT(@Lv_study_plan_code, ' - ', @Lv_study_plan_title)
DECLARE c_cursos_pendiente CURSOR FOR
Select SPC.course_code AS id_course,
CCC.code_course,
CCC.code_course,
dbo.F_GetNameCourse(code_course) as course_name,
SPC.credits --course_code
From study_plan_courses SPC
Left Join cat_courses_x_career CCC
On CCC.id = SPC.course_code
Where id_study_plan = @Lv_study_plan_code
And course_code NOT IN (
Select PC.code_course
From periods_courses_suscriptions PCS
Left Join periods_courses PC
On PC.id = PCS.id_periods_courses
Where PCS.[status] = 'A'
And PCS.[student_id] = @Ln_id_student
)
Order by SPC.[block], SPC.[order];
DECLARE @Ln_course_id INT;
DECLARE @Ln_course_code char(10);
DECLARE @Ln_career_code char(10);
DECLARE @Lv_course_name VARCHAR(400);
DECLARE @Lv_course_credits INT;
DECLARE @Ln_contador INT = 0;
OPEN c_cursos_pendiente
FETCH c_cursos_pendiente
INTO @Ln_course_id, @Ln_course_code,@Ln_career_code, @Lv_course_name, @Lv_course_credits;
-- Para cursor c_cursos_pendiente
WHILE @@FETCH_STATUS = 0
BEGIN
SET @Ln_contador = @Ln_contador +1;
PRINT CONCAT(CHAR(9), @Lv_course_name, ' creditos necesarios: ', @Lv_course_credits)
FETCH c_cursos_pendiente
INTO @Ln_course_id, @Ln_course_code,@Ln_career_code, @Lv_course_name, @Lv_course_credits;
END
CLOSE c_cursos_pendiente
DEALLOCATE c_cursos_pendiente
PRINT '__________________________'
PRINT CONCAT('Un total de ',@Ln_contador,' curso(s) pendiente(s) para ',@Lv_course_name,'.')
PRINT '__________________________'
SET @Ln_contador= 0
FETCH c_study_plan_suscriptions
INTO @Lv_study_plan_code, @Lv_study_plan_title, @Lv_study_plan_description;
END
CLOSE c_study_plan_suscriptions
DEALLOCATE c_study_plan_suscriptions
END;
EXEC P_GetMissingCourses 21;