-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStore Procedure.sql
More file actions
202 lines (118 loc) · 5.34 KB
/
Store Procedure.sql
File metadata and controls
202 lines (118 loc) · 5.34 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
--Store Procedure
USE ProyectoServiu;
GO
IF OBJECT_ID ('sp_serviu') IS NOT NULL
DROP PROCEDURE sp_serviu;
GO
CREATE PROCEDURE sp_serviu @año int , @rutIngresado int AS
BEGIN
Declare @total_carga int , @total_puntaje int;
set @total_carga = dbo.fc_count_carga(@rutIngresado);
set @total_puntaje = dbo.fc_puntaje_carga2(@total_carga);
insert into proceso (ano,rut_postulante,puntaje_carga,cantidad_cargas)values (@año,@rutIngresado,@total_puntaje,@total_carga);
END;
--Ejecutar storeprocedure
EXEC sp_serviu 2019,94737419;
--Consultar
select * from postulante;
select * from Proceso;
--Store Procedure (Prueba N° 2)
USE ProyectoServiu;
GO
IF OBJECT_ID ('sp_serviu2') IS NOT NULL
DROP PROCEDURE sp_serviu2;
GO
CREATE PROCEDURE sp_serviu2 @año int, @rutIngresado int
AS
BEGIN
Declare
@edad int , @puntajeEdad int ,
@cantidad_cargas int , @puntajeCargas int ,
@estado_civilVarchar varchar(50), @estado_civilInt int ,@puntaje_estado_civil int ,
@pueblo_indigena varchar(50), @pueblo_indigenaInt int , @puntaje_pueblo_indigena int,
@monto int, @puntaje_monto_ahorro int,
@tipo_titulo int , @puntaje_titulo int,
@total_puntaje int
set @Edad = dbo.fc_edad(@rutIngresado);
set @puntajeEdad = dbo.fc_puntaje_edad(@Edad);
set @cantidad_cargas = dbo.fc_cantidad_carga(@rutIngresado);
set @puntajeCargas = dbo.fc_puntaje_carga2(@cantidad_cargas);
set @estado_civilVarchar = dbo.fc_estado_civil(@rutIngresado);
set @estado_civilInt = dbo.fc_estado_civilInt(@rutIngresado);
set @puntaje_estado_civil = dbo.fc_puntaje_estado_civil(@estado_civilInt);
set @pueblo_indigena = dbo.fc_pueblo_originario(@rutIngresado);
set @pueblo_indigenaInt = dbo.fc_pueblo_originarioInt(@rutIngresado);
set @puntaje_pueblo_indigena = dbo.fc_puntaje_pueblo_originario(@pueblo_indigenaInt);
set @monto = dbo.fc_monto_ahorro(@rutIngresado);
set @puntaje_monto_ahorro = dbo.fc_puntaje_monto_ahorro(@monto);
set @tipo_titulo = dbo.fc_tipo_titulo(@rutIngresado);
set @puntaje_titulo = dbo.fc_puntaje_tipo_titulo(@tipo_titulo);
set @total_puntaje = SUM(@puntajeEdad + @puntajeCargas + @puntaje_estado_civil + @puntaje_pueblo_indigena + @puntaje_monto_ahorro + @puntaje_titulo );
insert into proceso (ano,rut_postulante,edad,puntaje_edad,cantidad_cargas,puntaje_carga,estado_civil,puntaje_estado_civil,pueblo_indigena,puntaje_pueblo_indigena,monto_ahorro,puntaje_monto_ahorro,puntaje_titulo,total_puntaje)
values(@año,@rutIngresado,@Edad,@puntajeEdad,@cantidad_cargas,@puntajeCargas,@estado_civilVarchar,@puntaje_estado_civil,@pueblo_indigena,@puntaje_pueblo_indigena,@monto,@puntaje_monto_ahorro,@puntaje_titulo,@total_puntaje);
END;
--Ejecutar storeprocedure y consultar
EXEC sp_serviu2 2019,171302838;
GO
select * from Proceso;
--Vaciar las tablas
delete from Proceso;
go
truncate table Proceso;
select * from postulante order by rut_postulante;
select * from postulante order by created_at;
select * from cuenta order by id_cuenta;
--Procedimiento con cursores.
USE ProyectoServiu;
GO
IF OBJECT_ID ('sp_serviu3') IS NOT NULL
DROP PROCEDURE sp_serviu3;
GO
create procedure sp_serviu3
as
declare @rutCursor int, @año int,
@edad int , @puntajeEdad int,
@cantidad_cargas int , @puntajeCargas int ,
@estado_civilVarchar varchar(50), @estado_civilInt int ,@puntaje_estado_civil int ,
@pueblo_indigena varchar(50), @pueblo_indigenaInt int , @puntaje_pueblo_indigena int,
@monto int, @puntaje_monto_ahorro int,
@tipo_titulo int , @puntaje_titulo int,
@total_puntaje int
declare MICURSOR cursor
for select rut_postulante from postulante
open MICURSOR
fetch next from MICURSOR into @rutCursor
while @@FETCH_STATUS=0
begin
set @año = '2019';
set @Edad = dbo.fc_edad(@rutCursor);
set @puntajeEdad = dbo.fc_puntaje_edad(@Edad);
set @cantidad_cargas = dbo.fc_cantidad_carga(@rutCursor);
set @puntajeCargas = dbo.fc_puntaje_carga2(@cantidad_cargas);
set @estado_civilVarchar = dbo.fc_estado_civil(@rutCursor);
set @estado_civilInt = dbo.fc_estado_civilInt(@rutCursor);
set @puntaje_estado_civil = dbo.fc_puntaje_estado_civil(@estado_civilInt);
set @pueblo_indigena = dbo.fc_pueblo_originario(@rutCursor);
set @pueblo_indigenaInt = dbo.fc_pueblo_originarioInt(@rutCursor);
set @puntaje_pueblo_indigena = dbo.fc_puntaje_pueblo_originario(@pueblo_indigenaInt);
set @monto = dbo.fc_monto_ahorro(@rutCursor);
set @puntaje_monto_ahorro = dbo.fc_puntaje_monto_ahorro(@monto);
set @tipo_titulo = dbo.fc_tipo_titulo(@rutCursor);
set @puntaje_titulo = dbo.fc_puntaje_tipo_titulo(@tipo_titulo);
set @total_puntaje = SUM(@puntajeEdad + @puntajeCargas + @puntaje_estado_civil + @puntaje_pueblo_indigena + @puntaje_monto_ahorro + @puntaje_titulo );
insert into proceso (ano,rut_postulante,edad,puntaje_edad,cantidad_cargas,puntaje_carga,estado_civil,puntaje_estado_civil,pueblo_indigena,puntaje_pueblo_indigena,monto_ahorro,puntaje_monto_ahorro,puntaje_titulo,total_puntaje)
values(@año,@rutCursor,@Edad,@puntajeEdad,@cantidad_cargas,@puntajeCargas,@estado_civilVarchar,@puntaje_estado_civil,@pueblo_indigena,@puntaje_pueblo_indigena,@monto,@puntaje_monto_ahorro,@puntaje_titulo,@total_puntaje);
fetch next from MICURSOR into @rutCursor
end
close MICURSOR
deallocate MICURSOR;
--Ejecutar storeprocedure y consultar
EXEC sp_serviu3;
GO
select * from Proceso order by total_puntaje desc;
--Vaciar las tablas
delete from Proceso;
go
truncate table Proceso;
--Consultar la tabla postulante
select * from postulante;