URGENTE! Valor numerico fuera del rango
Publicado por Carolina (150 intervenciones) el 02/09/2021 17:50:57
Hola amgos, tengo un problema que no puedo darme cuenta donde esta el problema: tengo un programa que maneja información de varios hoteles.Al ingresar a cada uno de ellos tengo una función que revisa y elimina las reservas que ya han pasado de fecha y no se han presentado en el hotel.Esta función anda bien para TODOS los hoteles MENOS PARA UNO y no me doy cuenta el porque
La funcion es la siguiente:
f_cancelar_reservas_viejas()
Long vid_reserva, v_error = 0, v_graba = 0, a_reservas[ ], cant, kk, vid_hab, hab_res[ ], areservas_vencer[ ], cant_2
Datetime vfecha_i, vf1, vfecha_f
String vid_estado, vres_quedan = '', vres_vencer = ''
Dec{2} v_anticipos
Select count(*) Into :cant From hmv_reservas where id_hotel = :vid_hotel_actual and (nro_orden_alojamiento = 0 OR nro_orden_alojamiento is null);
If cant = 0 then Return
Declare Prox_rsc Cursor For
Select id_reserva, fecha_i, fecha_f
From Hmv_reservas
Where id_hotel = :vid_hotel_actual and (nro_orden_alojamiento = 0 OR nro_orden_alojamiento is null) and tipo_reserva = 'C'
UNION
Select Hmv_habitaciones_reservadas.id_reserva, Min(Hmv_habitaciones_reservadas.fecha_i), Max(Hmv_habitaciones_reservadas.fecha_f)
From Hmv_reservas, Hmv_habitaciones_reservadas
Where hmv_reservas.id_hotel = :vid_hotel_actual and (nro_orden_alojamiento = 0 OR nro_orden_alojamiento is null) and tipo_reserva = 'P' and (hmv_habitaciones_reservadas.id_reserva = hmv_reservas.id_reserva)
group by hmv_habitaciones_reservadas.id_hotel, hmv_habitaciones_reservadas.id_reserva;
//order by hmv_reservas.fecha_i;
cant = 0
cant_2 = 0
Open prox_rsc;
//ACA ES DONDE ME SALE EL ERROR
Do While Sqlca.Sqlcode = 0
Fetch prox_rsc Into :vid_reserva, :vfecha_i, :vfecha_f;
If Sqlca.Sqlcode = 100 then exit
// If date(vfecha_i) < Today() then
//25/10/2009 Me pidio Beatriz que se cancelaran pero cuando pasaba la fecha de salida del hotel
If date(vfecha_f) <= Today() then
cant = cant + 1
a_reservas[cant] = vid_reserva
elseif date(vfecha_i) = Relativedate(Today(), 6) then
cant_2 = cant_2 + 1
areservas_vencer[cant_2] = vid_reserva
End if
Loop
If Sqlca.Sqlcode = -1 then
Messagebox("Error al buscar las reservas a cancelar", Sqlca.Sqlerrtext)
End if
Close prox_rsc;
//Ahora borro las reservas marcadas
If Upperbound(a_reservas) > 0 then
For cant = 1 to Upperbound(a_reservas)
vid_reserva = a_reservas[cant]
v_anticipos = 0
Select Sum(valor) Into :v_anticipos From Hmv_anticipos Where id_reserva = :vid_reserva;
If v_anticipos > 0 then
If vres_quedan <> '' then vres_quedan = vres_quedan + ' / '
vres_quedan = vres_quedan + String (vid_reserva)
else
Select fecha_i Into :vfecha_i From Hmv_reservas where id_hotel = :vid_hotel_actual and id_reserva = :vid_reserva;
hab_res = f_buscar_habitaciones(vid_reserva)
Delete From Hmv_reservas where id_hotel = :vid_hotel_actual and id_reserva = :vid_reserva;
If Sqlca.Sqlcode = -1 then
Messagebox("Error al eliminar la reserva de la tabla de Reservas", Sqlca.Sqlerrtext)
v_error = -1
exit
End if
Delete From Hmv_anticipos where id_hotel = :vid_hotel_actual and id_reserva = :vid_reserva;
If Sqlca.Sqlcode = -1 then
Messagebox("Error al eliminar el anticipo que tenía la Reserva", Sqlca.Sqlerrtext)
v_error = -1
exit
End if
//Ahora tengo que actualizar el estado de la habitacion
For kk = 1 To Upperbound(hab_res)
vid_hab = hab_res[kk]
Select id_estado, fec_ini_estado Into :vid_estado, :vf1 From Hmv_habitaciones where id_hotel = :vid_hotel_actual and id_habitacion = :vid_hab;
If (vid_estado = 'RC' OR vid_estado = 'RP') and vf1 = vfecha_i then
f_establecer_estado(vid_hab, vfecha_i)
end if
Next
End if
Next
End if
If Upperbound(areservas_vencer) > 0 then
For cant = 1 to Upperbound(areservas_vencer)
vid_reserva = areservas_vencer[cant]
v_anticipos = 0
Select Sum(valor) Into :v_anticipos From Hmv_anticipos Where id_reserva = :vid_reserva;
If v_anticipos > 0 then
If vres_vencer <> '' then vres_vencer = vres_vencer + ' / '
vres_vencer = vres_vencer + String (vid_reserva)
End if
Next
End if
If v_error = 0 then
Commit Using Sqlca;
// If vres_quedan <> '' then Messagebox("Reservas: " + vres_quedan,"Las siguientes reservas ya caducaron pero no se cancelaron porque tienen pagos pendientes a favor del pasajero.", Information!)
If vres_vencer <> '' then Messagebox("Reservas próximas a vencer" , "Las reservas " + vres_vencer + " caducan el dia " + String(RelativeDate(today(), 6)) + ".")
else
RollBack Using Sqlca;
End if
Esta función anda bien para cuando el ID_HOTEL_ACTUAL (que es una variable global) es por ejemplo = 1 y el SQL del cursor que declaro me devuelve por ejemplo estas filas:
191942 2021-10-07 12:00:00.000 2021-10-11 10:00:00.000
191978 2021-10-08 12:00:00.000 2021-10-11 10:00:00.000
192067 2021-10-08 12:00:00.000 2021-10-11 10:00:00.000
191936 2021-10-09 12:00:00.000 2021-10-11 10:00:00.000
191982 2021-12-19 12:00:00.000 2021-12-26 10:00:00.000
192010 2021-12-19 12:00:00.000 2021-12-26 10:00:00.000
192054 2021-12-19 12:00:00.000 2021-12-26 10:00:00.000
191984 2021-12-26 12:00:00.000 2022-01-02 10:00:00.000
192012 2021-12-26 12:00:00.000 2022-01-02 10:00:00.000
192055 2021-12-26 12:00:00.000 2022-01-02 10:00:00.000
191985 2022-01-02 12:00:00.000 2022-01-09 10:00:00.000
Y PARA TODOS LOS DEMAS HOTELES MENOS EL 15 ME FUNCIONA BIEN.aHORA EL HOTEL CUYO ID = 15 me devuelve estas filas:
192091 2021-09-18 12:00:00.000 2021-09-22 10:00:00.000
192092 2021-09-22 12:00:00.000 2021-09-24 10:00:00.000
y ya con estos 2 datos me da el error SQL STATE 22003 VALOR NUMERICO FUERA DEL INTERVALO.
Los datos devueltos son: Nro de reserva, fecha de ingreso y fecha de salida
Uso Power Builder 12.5 y SQL Server 2014
Muchas gracias al que pueda darme una mano!!!!!
Carolina
La funcion es la siguiente:
f_cancelar_reservas_viejas()
Long vid_reserva, v_error = 0, v_graba = 0, a_reservas[ ], cant, kk, vid_hab, hab_res[ ], areservas_vencer[ ], cant_2
Datetime vfecha_i, vf1, vfecha_f
String vid_estado, vres_quedan = '', vres_vencer = ''
Dec{2} v_anticipos
Select count(*) Into :cant From hmv_reservas where id_hotel = :vid_hotel_actual and (nro_orden_alojamiento = 0 OR nro_orden_alojamiento is null);
If cant = 0 then Return
Declare Prox_rsc Cursor For
Select id_reserva, fecha_i, fecha_f
From Hmv_reservas
Where id_hotel = :vid_hotel_actual and (nro_orden_alojamiento = 0 OR nro_orden_alojamiento is null) and tipo_reserva = 'C'
UNION
Select Hmv_habitaciones_reservadas.id_reserva, Min(Hmv_habitaciones_reservadas.fecha_i), Max(Hmv_habitaciones_reservadas.fecha_f)
From Hmv_reservas, Hmv_habitaciones_reservadas
Where hmv_reservas.id_hotel = :vid_hotel_actual and (nro_orden_alojamiento = 0 OR nro_orden_alojamiento is null) and tipo_reserva = 'P' and (hmv_habitaciones_reservadas.id_reserva = hmv_reservas.id_reserva)
group by hmv_habitaciones_reservadas.id_hotel, hmv_habitaciones_reservadas.id_reserva;
//order by hmv_reservas.fecha_i;
cant = 0
cant_2 = 0
Open prox_rsc;
//ACA ES DONDE ME SALE EL ERROR
Do While Sqlca.Sqlcode = 0
Fetch prox_rsc Into :vid_reserva, :vfecha_i, :vfecha_f;
If Sqlca.Sqlcode = 100 then exit
// If date(vfecha_i) < Today() then
//25/10/2009 Me pidio Beatriz que se cancelaran pero cuando pasaba la fecha de salida del hotel
If date(vfecha_f) <= Today() then
cant = cant + 1
a_reservas[cant] = vid_reserva
elseif date(vfecha_i) = Relativedate(Today(), 6) then
cant_2 = cant_2 + 1
areservas_vencer[cant_2] = vid_reserva
End if
Loop
If Sqlca.Sqlcode = -1 then
Messagebox("Error al buscar las reservas a cancelar", Sqlca.Sqlerrtext)
End if
Close prox_rsc;
//Ahora borro las reservas marcadas
If Upperbound(a_reservas) > 0 then
For cant = 1 to Upperbound(a_reservas)
vid_reserva = a_reservas[cant]
v_anticipos = 0
Select Sum(valor) Into :v_anticipos From Hmv_anticipos Where id_reserva = :vid_reserva;
If v_anticipos > 0 then
If vres_quedan <> '' then vres_quedan = vres_quedan + ' / '
vres_quedan = vres_quedan + String (vid_reserva)
else
Select fecha_i Into :vfecha_i From Hmv_reservas where id_hotel = :vid_hotel_actual and id_reserva = :vid_reserva;
hab_res = f_buscar_habitaciones(vid_reserva)
Delete From Hmv_reservas where id_hotel = :vid_hotel_actual and id_reserva = :vid_reserva;
If Sqlca.Sqlcode = -1 then
Messagebox("Error al eliminar la reserva de la tabla de Reservas", Sqlca.Sqlerrtext)
v_error = -1
exit
End if
Delete From Hmv_anticipos where id_hotel = :vid_hotel_actual and id_reserva = :vid_reserva;
If Sqlca.Sqlcode = -1 then
Messagebox("Error al eliminar el anticipo que tenía la Reserva", Sqlca.Sqlerrtext)
v_error = -1
exit
End if
//Ahora tengo que actualizar el estado de la habitacion
For kk = 1 To Upperbound(hab_res)
vid_hab = hab_res[kk]
Select id_estado, fec_ini_estado Into :vid_estado, :vf1 From Hmv_habitaciones where id_hotel = :vid_hotel_actual and id_habitacion = :vid_hab;
If (vid_estado = 'RC' OR vid_estado = 'RP') and vf1 = vfecha_i then
f_establecer_estado(vid_hab, vfecha_i)
end if
Next
End if
Next
End if
If Upperbound(areservas_vencer) > 0 then
For cant = 1 to Upperbound(areservas_vencer)
vid_reserva = areservas_vencer[cant]
v_anticipos = 0
Select Sum(valor) Into :v_anticipos From Hmv_anticipos Where id_reserva = :vid_reserva;
If v_anticipos > 0 then
If vres_vencer <> '' then vres_vencer = vres_vencer + ' / '
vres_vencer = vres_vencer + String (vid_reserva)
End if
Next
End if
If v_error = 0 then
Commit Using Sqlca;
// If vres_quedan <> '' then Messagebox("Reservas: " + vres_quedan,"Las siguientes reservas ya caducaron pero no se cancelaron porque tienen pagos pendientes a favor del pasajero.", Information!)
If vres_vencer <> '' then Messagebox("Reservas próximas a vencer" , "Las reservas " + vres_vencer + " caducan el dia " + String(RelativeDate(today(), 6)) + ".")
else
RollBack Using Sqlca;
End if
Esta función anda bien para cuando el ID_HOTEL_ACTUAL (que es una variable global) es por ejemplo = 1 y el SQL del cursor que declaro me devuelve por ejemplo estas filas:
191942 2021-10-07 12:00:00.000 2021-10-11 10:00:00.000
191978 2021-10-08 12:00:00.000 2021-10-11 10:00:00.000
192067 2021-10-08 12:00:00.000 2021-10-11 10:00:00.000
191936 2021-10-09 12:00:00.000 2021-10-11 10:00:00.000
191982 2021-12-19 12:00:00.000 2021-12-26 10:00:00.000
192010 2021-12-19 12:00:00.000 2021-12-26 10:00:00.000
192054 2021-12-19 12:00:00.000 2021-12-26 10:00:00.000
191984 2021-12-26 12:00:00.000 2022-01-02 10:00:00.000
192012 2021-12-26 12:00:00.000 2022-01-02 10:00:00.000
192055 2021-12-26 12:00:00.000 2022-01-02 10:00:00.000
191985 2022-01-02 12:00:00.000 2022-01-09 10:00:00.000
Y PARA TODOS LOS DEMAS HOTELES MENOS EL 15 ME FUNCIONA BIEN.aHORA EL HOTEL CUYO ID = 15 me devuelve estas filas:
192091 2021-09-18 12:00:00.000 2021-09-22 10:00:00.000
192092 2021-09-22 12:00:00.000 2021-09-24 10:00:00.000
y ya con estos 2 datos me da el error SQL STATE 22003 VALOR NUMERICO FUERA DEL INTERVALO.
Los datos devueltos son: Nro de reserva, fecha de ingreso y fecha de salida
Uso Power Builder 12.5 y SQL Server 2014
Muchas gracias al que pueda darme una mano!!!!!
Carolina
Valora esta pregunta
0