Estimados, la idea expuesta por fjcg02, podrías haber funcionado, pero tenia un problema es que el id_bodega está en 2 tablas.
El tema lo resolví de la siguiente forma lo expongo por si a alguien le sirve.
Modifique el procedimiento agregando una segunda variable de entrada de tipo varchar (1000), llamada texto. Esta la creo en tiempo de ejecucción con todas das las condiciones deseadas por el usuario.
Código SQL
[-]
create or alter procedure INVENTARIO_RESUMEN (
BODEGAS varchar(150),
TEXTO varchar(1000) = 0)
returns (
ID_ITEM bigint,
NOMBRE varchar(80),
PRECIO_MEDIO numeric(15,2),
CANTIDAD_INGRESO numeric(15,2),
CANTIDAD_EGRESO numeric(15,2),
ID_CLASIFICACION bigint,
PRECIO_EGRESO numeric(15,2))
as
begin
for execute statement :texto into :id_item, :nombre, :id_clasificacion do
begin
execute statement
'select coalesce(sum(cantidad * precio)/sum(iif(cantidad = 0,1,cantidad)),0),
coalesce(sum(cantidad),0) from inventario
where id_item ='||:id_item||' and id_bodega in '||(:bodegas)
into
recio_medio, :cantidad_ingreso;
execute statement
'select coalesce(avg(precio),0), coalesce(sum(cantidad),0) from inventario_egreso
where id_item ='||:id_item||' and id_bodega in '||(:bodegas)
into
recio_egreso, :cantidad_egreso;
suspend;
end
end
Funciona perfecto, y mejora notablemente la velocidad, ya que el query principal del procedimiento es sobre un numero limitado de registro, dadas las condiciones requeridas.
Saludos.