-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPunto_03.sql
More file actions
166 lines (138 loc) · 4.73 KB
/
Copy pathPunto_03.sql
File metadata and controls
166 lines (138 loc) · 4.73 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
/*
Reporte de profesores por curso. Utilizar Cursor
Se desea conocer de un profesor: Los cursos que ha impartido en la historia,
su antigüedad como profesor y un promedio de sus evaluaciones de desempeño.
Consultar por rango de años.
*/
CREATE OR ALTER PROCEDURE P_GetTeacherHistory
@Ln_id_teacher INT,
@Lv_start_year CHAR(4) = NULL,
@Lv_end_year CHAR(4) = NULL
AS
DECLARE c_evaluations CURSOR FOR
Select
PE.id,
PE.id_user,
PE.[start_date],
PE.[end_date],
PE.reason,
AVG(PED.score) As Score,
COUNT(1) as TotalReviews
From [performance_evaluation] PE
Left Join [performance_evaluation_details] PED
On PED.id_performance_evaluation = PE.ID
Where PE.id_user = @Ln_id_teacher
Group By PE.id, PE.id_user,PE.[start_date],PE.[end_date], PE.reason;
DECLARE @Lv_code_course CHAR(10);
DECLARE @Lv_course_name VARCHAR(100);
DECLARE @Lv_course_description VARCHAR(200);
DECLARE @Ld_last_date_curse DATETIME;
DECLARE @Ld_first_date_curse DATETIME;
DECLARE @Ln_name_teacher 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;
-- Cursor recupera los cursos impartidos por el profesor
DECLARE c_courses_teacher CURSOR FOR
Select
--PC.id_teacher,
CC.code,
CC.[name],
CC.[description]
From periods_courses PC
Left Join [periods] P
On P.id = PC.id_periods
Left Join cat_courses_x_career CCC
Left Join cat_courses CC
On CC.code = CCC.code_course
On CCC.id = PC.code_course
Where PC.id_teacher = @Ln_id_teacher
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
)
Group By PC.id_teacher , CC.code, CC.[name], CC.[description];
SET @Ln_name_teacher = dbo.F_GetCompleteNameUser(@Ln_id_teacher);
Select
@Ld_first_date_curse = MIN(P.[start_date ]),
@Ld_last_date_curse = MAX(P.[start_date ])
From periods_courses PC
Left Join [periods] P
On P.id = PC.id_periods
Where PC.id_teacher = @Ln_id_teacher;
PRINT CONCAT('Reporte de historia del profesor ',@Ln_name_teacher, ', del año ', @Lv_start_year, ' al ', @Lv_start_year, '.' )
PRINT CONCAT('El primer curso que impartio fue en ',CONVERT(VARCHAR, @Ld_first_date_curse, 1) )
PRINT CONCAT('El ultimo curso impartido fue en ',CONVERT(VARCHAR, @Ld_last_date_curse, 1) )
OPEN c_courses_teacher
FETCH c_courses_teacher
INTO @Lv_code_course , @Lv_course_name , @Lv_course_description;
BEGIN
DECLARE @Ln_contador_cursos INT =0;
PRINT 'Cursos que ha impartido:'
-- Para cursor c_courses_teacher
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT CONCAT(CHAR(9),'(',trim(@Lv_code_course),')' ,' ', @Lv_course_name )
FETCH c_courses_teacher
INTO @Lv_code_course , @Lv_course_name , @Lv_course_description;
SET @Ln_contador_cursos= @Ln_contador_cursos +1;
END
PRINT CONCAT('Total de cursos impartidos: ',@Ln_contador_cursos)
PRINT '____________________'
CLOSE c_courses_teacher
DEALLOCATE c_courses_teacher
END
BEGIN
DECLARE @Ln_id_evalation INT;
DECLARE @Ln_id_user_evalation INT;
DECLARE @Ln_start_date_evaluation DATETIME;
DECLARE @Ln_end_date_evaluation DATETIME;
DECLARE @Lv_reason_evaluation VARCHAR(2100);
DECLARE @Ln_score_evaluation INT;
DECLARE @Ln_total_reviews_evaluation INT;
PRINT 'Datos sobre evaluaciones:'
OPEN c_evaluations;
FETCH c_evaluations
INTO @Ln_id_evalation,
@Ln_id_user_evalation,
@Ln_start_date_evaluation,
@Ln_end_date_evaluation,
@Lv_reason_evaluation,
@Ln_score_evaluation,
@Ln_total_reviews_evaluation;
-- Para cursor c_evaluations
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT CONCAT(CHAR(9),'Evaluación #',@Ln_id_evalation)
PRINT CONCAT(CHAR(9),'Habilitada desde ',CONVERT(VARCHAR, @Ln_start_date_evaluation, 1), ' hasta ', CONVERT(VARCHAR, @Ln_start_date_evaluation, 1), '.')
PRINT CONCAT(CHAR(9),'Puntuación: ',@Ln_score_evaluation)
PRINT CONCAT(CHAR(9),'Total de evalaciones: ', @Ln_total_reviews_evaluation)
PRINT CONCAT(CHAR(9),'Razón: ',@Lv_reason_evaluation)
PRINT '_____________________________________'
FETCH c_evaluations
INTO @Ln_id_evalation,
@Ln_id_user_evalation,
@Ln_start_date_evaluation,
@Ln_end_date_evaluation,
@Lv_reason_evaluation,
@Ln_score_evaluation,
@Ln_total_reviews_evaluation;
END;
CLOSE c_evaluations
DEALLOCATE c_evaluations
END;
END;
EXEC P_GetTeacherHistory 21;
EXEC P_GetTeacherHistory 21, '2019', '2022';