AYUDA URGENTE STORE PROCEDURE
Publicado por Edgar (87 intervenciones) el 22/05/2007 22:54:17
AMIGOS DEL FOR NECESITO SU AYUDA URGENTE PUES EN LA EMPRESA EN DONDE TRABAJO PARA OBTENER UN REPORTE UTILIZAN UN SP QUE LA VERDAD YO NUNCA LO HE UTILIZADO AHORA DESEO QUE EN ESTE REPORTE OSEA EN ESTE SP APARESCAN LOS TIPOS DE CONTRATO ES DECIR ME AGRUPE POR TIPO DE CONTRATO . LES AGRADESCO MUCHO POR SU AYUDA , POR FAVOR LES ENVIO EL SP QUE ESTAMOS UTILIZANDO
create procedure "informix".sp_r_rol_gen_a_dcfi(an_cod_empr integer, an_anio integer, an_mes integer, an_cod_sucu integer, as_cod_estr char(10), as_cod_trub char(1), as_estado char(1), as_tcon char(1))
returning char(50), char(60), char(10), char(50), decimal(18,2),char(10),date;
define ls_des_estr char(50);
define ls_cod_empl char(10);
define ls_ape_empl char(30);
define ls_nom_empl char(30);
define ls_tipo char(10);
define ls_des_rubr char(50);
define ld_valor decimal(18,2);
define ls_nombres char(60);
define ls_tipo_aux char(1);
define ls_estado char(1);
define periodo integer;
define l_fecha_salida date;
--aumento cargo y fecha ingreso
define ls_nombre_cargo char(10);
define l_fecha_ingreso date;
let periodo = an_anio * 100 + an_mes;
if as_estado='L' then
let ls_estado='L';
else
let ls_estado = 'R';
end if;
if as_tcon ='%' then
-- liquidados
if ls_estado = 'L' then
select nombre_departamento, codigo_empleado, nombre_empleado,
case rubr_cod_trub
when 'I' then 'BENEFICIOS'
when 'D' then 'DESCUENTOS' END tipo,
rubr_des_alia,
case rubr_cod_trub
when 'I' then pago_val_pago
when 'D' then - pago_val_pago end valor,
--aumento cargo y fecha ingreso
nombre_cargo,
fecha_ingreso
from v_empleados_departamento, saeempl, saepago, saerubr
where codigo_empleado = empl_cod_empl
and codigo_empresa = empl_cod_empr
and codigo_empleado = pago_cod_empl
and codigo_empresa = pago_cod_empr
and pago_cod_rubr = rubr_cod_rubr
and pago_cod_empr = rubr_cod_empr
and codigo_departamento like as_cod_estr
and codigo_sucursal = an_cod_sucu
and codigo_empresa = an_cod_empr
and pago_ori_gene = ls_estado
and year(fecha_salida) * 100 + month(fecha_salida) <= periodo
and pago_per_pago = periodo
and rubr_cod_trub = as_cod_trub
and rubr_rol_desp = '1'
and (empl_cod_tcon like as_tcon or empl_cod_tcon is null)
into temp t_rol_gen_l;
else -- activos
select nombre_departamento, codigo_empleado, nombre_empleado,
case rubr_cod_trub
when 'I' then 'BENEFICIOS'
when 'D' then 'DESCUENTOS' END tipo,
rubr_des_alia,
case rubr_cod_trub
when 'I' then pago_val_pago
when 'D' then - pago_val_pago end valor,
--aumento cargo y fecha ingreso
nombre_cargo,
fecha_ingreso
from v_empleados_departamento, saeempl, saepago, saerubr
where codigo_empleado = empl_cod_empl
and codigo_empresa = empl_cod_empr
and codigo_empleado = pago_cod_empl
and codigo_empresa = pago_cod_empr
and pago_cod_rubr = rubr_cod_rubr
and pago_cod_empr = rubr_cod_empr
and codigo_departamento like as_cod_estr
and codigo_sucursal = an_cod_sucu
and codigo_empresa = an_cod_empr
and pago_ori_gene = ls_estado
and pago_per_pago = periodo
and rubr_cod_trub = as_cod_trub
and rubr_rol_desp = '1'
and (empl_cod_tcon like as_tcon or empl_cod_tcon is null)
into temp t_rol_gen_l;
end if;
else
-- liquidados
if ls_estado = 'L' then
select nombre_departamento, codigo_empleado, nombre_empleado,
case rubr_cod_trub
when 'I' then 'BENEFICIOS'
when 'D' then 'DESCUENTOS' END tipo,
rubr_des_alia,
case rubr_cod_trub
when 'I' then pago_val_pago
when 'D' then - pago_val_pago end valor,
--aumento cargo y fecha ingreso
nombre_cargo,
fecha_ingreso
from v_empleados_departamento, saeempl, saepago, saerubr
where codigo_empleado = empl_cod_empl
and codigo_empresa = empl_cod_empr
and codigo_empleado = pago_cod_empl
and codigo_empresa = pago_cod_empr
and pago_cod_rubr = rubr_cod_rubr
and pago_cod_empr = rubr_cod_empr
and codigo_departamento like as_cod_estr
and codigo_sucursal = an_cod_sucu
and codigo_empresa = an_cod_empr
and pago_ori_gene = ls_estado
and year(fecha_salida) * 100 + month(fecha_salida) <= periodo
and pago_per_pago = periodo
and rubr_cod_trub = as_cod_trub
and rubr_rol_desp = '1'
and empl_cod_tcon like as_tcon
into temp t_rol_gen_l;
else -- activos
select nombre_departamento, codigo_empleado, nombre_empleado,
case rubr_cod_trub
when 'I' then 'BENEFICIOS'
when 'D' then 'DESCUENTOS' END tipo,
rubr_des_alia,
case rubr_cod_trub
when 'I' then pago_val_pago
when 'D' then - pago_val_pago end valor,
--aumento cargo y fecha ingreso
nombre_cargo,
fecha_ingreso
from v_empleados_departamento, saeempl, saepago, saerubr
where codigo_empleado = empl_cod_empl
and codigo_empresa = empl_cod_empr
and codigo_empleado = pago_cod_empl
and codigo_empresa = pago_cod_empr
and pago_cod_rubr = rubr_cod_rubr
and pago_cod_empr = rubr_cod_empr
and codigo_departamento like as_cod_estr
and codigo_sucursal = an_cod_sucu
and codigo_empresa = an_cod_empr
and pago_ori_gene = ls_estado
and pago_per_pago = periodo
and rubr_cod_trub = as_cod_trub
and rubr_rol_desp = '1'
and empl_cod_tcon like as_tcon
into temp t_rol_gen_l;
end if;
end if
if as_cod_trub = 'I' then
-- liquidados
if ls_estado = 'L' then
foreach
select distinct codigo_empleado, fecha_salida
into ls_cod_empl, l_fecha_salida
from v_empleados_departamento, saepago
where codigo_empleado = pago_cod_empl
and codigo_empresa = pago_cod_empr
and codigo_departamento like as_cod_estr
and codigo_sucursal = an_cod_sucu
and codigo_empresa = an_cod_empr
and pago_ori_gene = ls_estado
and pago_per_pago = periodo
and year(fecha_salida) * 100 + month(fecha_salida) <= periodo
insert into t_rol_gen_l
select nombre_departamento, codigo_empleado, nombre_empleado,
'BENEFICIOS',
rubr_des_alia,
sum(pemp_val_mese),
--aumento cargo y fecha ingreso
nombre_cargo,
fecha_ingreso
from v_empleados_departamento, saepemp, saepnom, saerubr
where pemp_cod_empl = codigo_empleado
and pemp_cod_empr = codigo_empresa
and pemp_cod_pnom = pnom_cod_pnom
and pemp_cod_empr = pnom_cod_empr
and pnom_cod_rubr = rubr_cod_rubr
and pnom_cod_empr = rubr_cod_empr
and pemp_cod_empl = ls_cod_empl
and pemp_cod_empr = an_cod_empr
and pemp_fec_liqu = l_fecha_salida
and pnom_pro_desp = '1'
group by nombre_departamento, codigo_empleado, nombre_empleado, rubr_des_alia;
end foreach;
end if;
-- liquidados y activos
foreach
select nombre_departamento, codigo_empleado, nombre_empleado, nombre_cargo, fecha_ingreso
into ls_des_estr, ls_cod_empl, ls_nombres,ls_nombre_cargo,l_fecha_ingreso
from t_rol_gen_l
group by nombre_departamento, codigo_empleado, nombre_empleado
order by codigo_empleado
if as_cod_trub = 'I' then
let ls_tipo_aux = 'D';
let ls_tipo = 'DESCUENTOS';
else
let ls_tipo_aux = 'I';
let ls_tipo = 'BENEFICIOS';
end if;
select sum(pago_val_pago) into ld_valor
from saepago, saerubr
where pago_cod_rubr = rubr_cod_rubr
and pago_cod_empr = rubr_cod_empr
and pago_cod_empl = ls_cod_empl
and pago_cod_empr = an_cod_empr
and pago_per_pago = periodo
and rubr_cod_trub = ls_tipo_aux
and rubr_rol_desp = '1';
if ld_valor is null then
let ld_valor = 0;
end if;
if as_cod_trub = 'I' then
let ld_valor = - ld_valor;
end if;
insert into t_rol_gen_l
values(ls_des_estr, ls_cod_empl, ls_nombres, ls_tipo, ls_tipo, ld_valor,ls_nombre_cargo,l_fecha_ingreso);
end foreach;
end if;
foreach
select *
into ls_des_estr, ls_cod_empl, ls_nombres, ls_tipo, ls_des_rubr, ld_valor,ls_nombre_cargo,l_fecha_ingreso
from t_rol_gen_l
return ls_des_estr, ls_nombres, ls_tipo, ls_des_rubr, ld_valor,ls_nombre_cargo,l_fecha_ingreso with resume;
end foreach;
drop table t_rol_gen_l;
end procedure
create procedure "informix".sp_r_rol_gen_a_dcfi(an_cod_empr integer, an_anio integer, an_mes integer, an_cod_sucu integer, as_cod_estr char(10), as_cod_trub char(1), as_estado char(1), as_tcon char(1))
returning char(50), char(60), char(10), char(50), decimal(18,2),char(10),date;
define ls_des_estr char(50);
define ls_cod_empl char(10);
define ls_ape_empl char(30);
define ls_nom_empl char(30);
define ls_tipo char(10);
define ls_des_rubr char(50);
define ld_valor decimal(18,2);
define ls_nombres char(60);
define ls_tipo_aux char(1);
define ls_estado char(1);
define periodo integer;
define l_fecha_salida date;
--aumento cargo y fecha ingreso
define ls_nombre_cargo char(10);
define l_fecha_ingreso date;
let periodo = an_anio * 100 + an_mes;
if as_estado='L' then
let ls_estado='L';
else
let ls_estado = 'R';
end if;
if as_tcon ='%' then
-- liquidados
if ls_estado = 'L' then
select nombre_departamento, codigo_empleado, nombre_empleado,
case rubr_cod_trub
when 'I' then 'BENEFICIOS'
when 'D' then 'DESCUENTOS' END tipo,
rubr_des_alia,
case rubr_cod_trub
when 'I' then pago_val_pago
when 'D' then - pago_val_pago end valor,
--aumento cargo y fecha ingreso
nombre_cargo,
fecha_ingreso
from v_empleados_departamento, saeempl, saepago, saerubr
where codigo_empleado = empl_cod_empl
and codigo_empresa = empl_cod_empr
and codigo_empleado = pago_cod_empl
and codigo_empresa = pago_cod_empr
and pago_cod_rubr = rubr_cod_rubr
and pago_cod_empr = rubr_cod_empr
and codigo_departamento like as_cod_estr
and codigo_sucursal = an_cod_sucu
and codigo_empresa = an_cod_empr
and pago_ori_gene = ls_estado
and year(fecha_salida) * 100 + month(fecha_salida) <= periodo
and pago_per_pago = periodo
and rubr_cod_trub = as_cod_trub
and rubr_rol_desp = '1'
and (empl_cod_tcon like as_tcon or empl_cod_tcon is null)
into temp t_rol_gen_l;
else -- activos
select nombre_departamento, codigo_empleado, nombre_empleado,
case rubr_cod_trub
when 'I' then 'BENEFICIOS'
when 'D' then 'DESCUENTOS' END tipo,
rubr_des_alia,
case rubr_cod_trub
when 'I' then pago_val_pago
when 'D' then - pago_val_pago end valor,
--aumento cargo y fecha ingreso
nombre_cargo,
fecha_ingreso
from v_empleados_departamento, saeempl, saepago, saerubr
where codigo_empleado = empl_cod_empl
and codigo_empresa = empl_cod_empr
and codigo_empleado = pago_cod_empl
and codigo_empresa = pago_cod_empr
and pago_cod_rubr = rubr_cod_rubr
and pago_cod_empr = rubr_cod_empr
and codigo_departamento like as_cod_estr
and codigo_sucursal = an_cod_sucu
and codigo_empresa = an_cod_empr
and pago_ori_gene = ls_estado
and pago_per_pago = periodo
and rubr_cod_trub = as_cod_trub
and rubr_rol_desp = '1'
and (empl_cod_tcon like as_tcon or empl_cod_tcon is null)
into temp t_rol_gen_l;
end if;
else
-- liquidados
if ls_estado = 'L' then
select nombre_departamento, codigo_empleado, nombre_empleado,
case rubr_cod_trub
when 'I' then 'BENEFICIOS'
when 'D' then 'DESCUENTOS' END tipo,
rubr_des_alia,
case rubr_cod_trub
when 'I' then pago_val_pago
when 'D' then - pago_val_pago end valor,
--aumento cargo y fecha ingreso
nombre_cargo,
fecha_ingreso
from v_empleados_departamento, saeempl, saepago, saerubr
where codigo_empleado = empl_cod_empl
and codigo_empresa = empl_cod_empr
and codigo_empleado = pago_cod_empl
and codigo_empresa = pago_cod_empr
and pago_cod_rubr = rubr_cod_rubr
and pago_cod_empr = rubr_cod_empr
and codigo_departamento like as_cod_estr
and codigo_sucursal = an_cod_sucu
and codigo_empresa = an_cod_empr
and pago_ori_gene = ls_estado
and year(fecha_salida) * 100 + month(fecha_salida) <= periodo
and pago_per_pago = periodo
and rubr_cod_trub = as_cod_trub
and rubr_rol_desp = '1'
and empl_cod_tcon like as_tcon
into temp t_rol_gen_l;
else -- activos
select nombre_departamento, codigo_empleado, nombre_empleado,
case rubr_cod_trub
when 'I' then 'BENEFICIOS'
when 'D' then 'DESCUENTOS' END tipo,
rubr_des_alia,
case rubr_cod_trub
when 'I' then pago_val_pago
when 'D' then - pago_val_pago end valor,
--aumento cargo y fecha ingreso
nombre_cargo,
fecha_ingreso
from v_empleados_departamento, saeempl, saepago, saerubr
where codigo_empleado = empl_cod_empl
and codigo_empresa = empl_cod_empr
and codigo_empleado = pago_cod_empl
and codigo_empresa = pago_cod_empr
and pago_cod_rubr = rubr_cod_rubr
and pago_cod_empr = rubr_cod_empr
and codigo_departamento like as_cod_estr
and codigo_sucursal = an_cod_sucu
and codigo_empresa = an_cod_empr
and pago_ori_gene = ls_estado
and pago_per_pago = periodo
and rubr_cod_trub = as_cod_trub
and rubr_rol_desp = '1'
and empl_cod_tcon like as_tcon
into temp t_rol_gen_l;
end if;
end if
if as_cod_trub = 'I' then
-- liquidados
if ls_estado = 'L' then
foreach
select distinct codigo_empleado, fecha_salida
into ls_cod_empl, l_fecha_salida
from v_empleados_departamento, saepago
where codigo_empleado = pago_cod_empl
and codigo_empresa = pago_cod_empr
and codigo_departamento like as_cod_estr
and codigo_sucursal = an_cod_sucu
and codigo_empresa = an_cod_empr
and pago_ori_gene = ls_estado
and pago_per_pago = periodo
and year(fecha_salida) * 100 + month(fecha_salida) <= periodo
insert into t_rol_gen_l
select nombre_departamento, codigo_empleado, nombre_empleado,
'BENEFICIOS',
rubr_des_alia,
sum(pemp_val_mese),
--aumento cargo y fecha ingreso
nombre_cargo,
fecha_ingreso
from v_empleados_departamento, saepemp, saepnom, saerubr
where pemp_cod_empl = codigo_empleado
and pemp_cod_empr = codigo_empresa
and pemp_cod_pnom = pnom_cod_pnom
and pemp_cod_empr = pnom_cod_empr
and pnom_cod_rubr = rubr_cod_rubr
and pnom_cod_empr = rubr_cod_empr
and pemp_cod_empl = ls_cod_empl
and pemp_cod_empr = an_cod_empr
and pemp_fec_liqu = l_fecha_salida
and pnom_pro_desp = '1'
group by nombre_departamento, codigo_empleado, nombre_empleado, rubr_des_alia;
end foreach;
end if;
-- liquidados y activos
foreach
select nombre_departamento, codigo_empleado, nombre_empleado, nombre_cargo, fecha_ingreso
into ls_des_estr, ls_cod_empl, ls_nombres,ls_nombre_cargo,l_fecha_ingreso
from t_rol_gen_l
group by nombre_departamento, codigo_empleado, nombre_empleado
order by codigo_empleado
if as_cod_trub = 'I' then
let ls_tipo_aux = 'D';
let ls_tipo = 'DESCUENTOS';
else
let ls_tipo_aux = 'I';
let ls_tipo = 'BENEFICIOS';
end if;
select sum(pago_val_pago) into ld_valor
from saepago, saerubr
where pago_cod_rubr = rubr_cod_rubr
and pago_cod_empr = rubr_cod_empr
and pago_cod_empl = ls_cod_empl
and pago_cod_empr = an_cod_empr
and pago_per_pago = periodo
and rubr_cod_trub = ls_tipo_aux
and rubr_rol_desp = '1';
if ld_valor is null then
let ld_valor = 0;
end if;
if as_cod_trub = 'I' then
let ld_valor = - ld_valor;
end if;
insert into t_rol_gen_l
values(ls_des_estr, ls_cod_empl, ls_nombres, ls_tipo, ls_tipo, ld_valor,ls_nombre_cargo,l_fecha_ingreso);
end foreach;
end if;
foreach
select *
into ls_des_estr, ls_cod_empl, ls_nombres, ls_tipo, ls_des_rubr, ld_valor,ls_nombre_cargo,l_fecha_ingreso
from t_rol_gen_l
return ls_des_estr, ls_nombres, ls_tipo, ls_des_rubr, ld_valor,ls_nombre_cargo,l_fecha_ingreso with resume;
end foreach;
drop table t_rol_gen_l;
end procedure
Valora esta pregunta
0