Tengo un inconveniente.. Logre hacer un procedimiento que me calcule las quincenas.. funciona de maravilla cuando hago que recorra una tabla.. Ahi viene el problema.. debo hacer que recorra una vista.. le paso los parametros pero cuando lo ejecuto me sale null.. Me podrian ayudar x favor.. ya tengo dias con esto.. Xfaa
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_prueba_2`(out valor_retorno int)
BEGIN
DECLARE Nombre_Empleado varchar(60);
DECLARE Nombre_Empresa varchar(60);
DECLARE Division varchar(60);
DECLARE Subdivision varchar(60);
DECLARE Cargo varchar(60);
DECLARE Nombre_Jefe varchar(60);
DECLARE Fecha_Desde date;
DECLARE Fecha_Hasta date;
DECLARE borrar int ;
DECLARE c1 cursor for
SELECT Nombre_Empleado, Nombre_Empresa, Division, Subdivision, Cargo, Nombre_Jefe, Fecha_Desde, Fecha_Hasta from v_asignacion_recursos;
DECLARE EXIT HANDLER FOR sqlstate '02000' SET valor_retorno =1;
DECLARE EXIT HANDLER FOR sqlexception #SET valor_retorno = 1;
BEGIN
SET valor_retorno = 0;
END;
set borrar= 0;
open c1;
c1_loop: LOOP
fetch c1 into Nombre_Empleado, Nombre_Empresa, Division, Subdivision, Cargo, Nombre_Jefe, Fecha_Desde, Fecha_Hasta;
SELECT @empleado := Nombre_Empleado;-- empleado_his from asignacion_recursos_his where id_asignacionrecursos_his = id_asignacion;
SELECT @fecha_desde := Fecha_Desde; -- fechaDesde_his from asignacion_recursos_his where id_asignacionrecursos_his = id_asignacion;
SELECT @fecha_hasta := Fecha_Hasta; -- fechaHasta_his from asignacion_recursos_his where id_asignacionrecursos_his = id_asignacion;
SELECT @fechaAuxDesde := Fecha_Desde; -- fechaDesde_his from asignacion_recursos_his where id_asignacionrecursos_his = id_asignacion;
SELECT @fecha_act := curdate();
if borrar=0 then
SET SQL_SAFE_UPDATES=0;
DELETE from reporte_asi where fecha_generacion=@fecha_act;
end if;
if @fecha_hasta = null then
select @fecha_hasta := concat(DATE_FORMAT(now(), '%Y-%m-'),day(last_day(now())));
end if;
WHILE @fechaAuxDesde <= @fecha_hasta DO
select @fecha_inicio_p := null;
select @fecha_fin_p := null;
select @fecha_inicio_s := null;
select @fecha_fin_s := null;
if day(@fechaAuxDesde) < 15 then
if day(@fechaAuxDesde) < 15 then
select @fecha_inicio_p := @fechaAuxDesde;
select @fecha_fin_p := concat(DATE_FORMAT(@fechaAuxDesde, '%Y-%m-'),15);
end if;
if @fecha_fin_p < @fecha_hasta then
if(month(@fecha_fin_p) = month(@fecha_hasta) and year(@fecha_fin_p) = year(@fecha_hasta)) then
select @fecha_inicio_s := adddate(@fecha_fin_p, interval 1 day);
select @fecha_fin_s := @fecha_hasta;
else
select @fecha_inicio_s := adddate(@fecha_fin_p, interval 1 day);
select @fecha_fin_s := concat(DATE_FORMAT(@fecha_fin_p, '%Y-%m-'),day(last_day(@fecha_fin_p)));
end if;
end if;
else
if day(@fechaAuxDesde) >= 15 then
select @fecha_inicio_s := @fechaAuxDesde;
select @fecha_fin_s := concat(DATE_FORMAT(@fechaAuxDesde, '%Y-%m-'),day(last_day(@fechaAuxDesde)));
end if;
end if;
-- INSERT INTO perseo.reporte_asi(empleado, inicio_p, fin_p, inicio_s, fin_s, fecha_generacion) VALUES (@empleado, @fecha_inicio_p, @fecha_fin_p, @fecha_inicio_s, @fecha_fin_s, @fecha_act);-- , @fecha_desde, @P_Quincena);
set @fechaAuxDesde := DATE_FORMAT(adddate(@fechaAuxDesde, interval 1 month),'%Y-%m-01');
END WHILE;
set borrar=borrar+1;
#IF `done` THEN LEAVE c1_loop; END IF;
IF `valor_retorno`=0 THEN LEAVE c1_loop; END IF;
END LOOP c1_loop;
CLOSE c1;
END