Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » Mysql »

Variables en procedimiento

Estas en el tema de Variables en procedimiento en el foro de Mysql en Foros del Web. Hola amigos como les va? Bueno aca tengo un procedimiento que segun los parametros va a devolver las ventas de entre fecha desde y hasta, ...
  #1 (permalink)  
Antiguo 28/01/2009, 08:23
mgd
 
Fecha de Ingreso: enero-2009
Mensajes: 129
Antigüedad: 15 años, 3 meses
Puntos: 0
Variables en procedimiento

Hola amigos como les va?

Bueno aca tengo un procedimiento que segun los parametros va a devolver las ventas de entre fecha desde y hasta, la sucursal y el tipo

E = efectivo
T = Tarjeta
C = Cuenta

en la variable tipo de paso el parametro de lo que necesito
y esa variable es controlada con los if para ver que se necesita

el tema es que le pase el parametro que le pase siempre trae todas las ventas de esas fechas, es decir que si tipo es E o C o T o cualquier conjugacion siempre trae todo

cual es el error ???
como puedo hacerlo con CASE ???


Código:
CREATE DEFINER=`root`@`localhost` PROCEDURE `consultacajaventas`(fechac1 datetime, fechac2 datetime, sucursalc varchar(1), tipoc varchar(3))
BEGIN
declare tipo varchar(3);
set tipo = tipoc;
if tipo = 'E' then
select codventa, importetotal from ventas where estado <> 'baja' and tipo = 'E' and sucursal = sucursalc and fecha between fechac1 and fechac2;
end if;
if tipo = 'T' then
select codventa, importetotal from ventas where estado <> 'baja' and tipo = 'T' and sucursal = sucursalc and fecha between fechac1 and fechac2;
end if;
if tipo = 'C' then
select codventa, importetotal from ventas where estado <> 'baja' and tipo = 'C' and sucursal = sucursalc and fecha between fechac1 and fechac2;
end if;
if tipo = 'ET' then
select codventa, importetotal from ventas where estado <> 'baja' and tipo <> 'C' and sucursal = sucursalc and fecha between fechac1 and fechac2;
end if;
if tipo = 'ETC' then
select codventa, importetotal from ventas where estado <> 'baja' and sucursal = sucursalc and fecha between fechac1 and fechac2;
end if;
if tipo = 'EC' then
select codventa, importetotal from ventas where estado <> 'baja' and tipo <> 'T' and sucursal = sucursalc and fecha between fechac1 and fechac2;
end if;
if tipo = 'TC' then
select codventa, importetotal from ventas where estado <> 'baja' and tipo <> 'E' and sucursal = sucursalc and fecha between fechac1 and fechac2;
end if;
end
Muchas gracias por su ayuda
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:15.