jajaj ahora tengo otro problema resulta que al concatenar la variable me tira un resultado que no me sirve pero al no concatenar me tira bien el resultado
creo que se explica mejor con el codigo
CONCATENADO alias (No me sirve el resultado)
Código SQL:
Ver originalCREATE OR REPLACE FUNCTION prueba(idTaller INTEGER,IN alias VARCHAR(255),OUT VehiculosTaller BIGINT,OUT CapacidadTaller SMALLINT) RETURNS SETOF RECORD AS $BODY$
DECLARE
use_sql TEXT;
BEGIN
use_sql := 'select count(VEHICULOS.id_vehiculo)as VehiculosTaller,locales.capacidad_instalada as CapacidadTaller from SINIESTROS,COMPANIAS,VEHICULOS,LOCALES,TALLERES
where SINIESTROS.id_compania = COMPANIAS.id_compania and SINIESTROS.id_vehiculo = VEHICULOS.id_vehiculo and VEHICULOS.id_estado <> 12 and
VEHICULOS.id_local = LOCALES.id_local and LOCALES.id_taller = TALLERES.id_taller and TALLERES.id_taller = '||idTaller||' and
COMPANIAS.alias = upper('||'alias'||')group by locales.capacidad_instalada UNION ALL
select count(VEHICULOS.id_vehiculo),locales.capacidad_instalada from SINIESTROS,COMPANIAS,VEHICULOS,LOCALES,TALLERES
where SINIESTROS.id_compania = COMPANIAS.id_compania and SINIESTROS.id_vehiculo = VEHICULOS.id_vehiculo and VEHICULOS.id_estado <> 12 and
VEHICULOS.id_local = LOCALES.id_local and LOCALES.id_taller = TALLERES.id_taller and TALLERES.id_taller = '||idTaller||' and COMPANIAS.alias <> upper('||'alias'||')
group by locales.capacidad_instalada';
RETURN QUERY EXECUTE use_sql;
END;
$BODY$
LANGUAGE plpgsql;
SELECT * FROM prueba (5,'bci');
VehiculosTaller CapacidadTaller
--------------------- ---------------------------
3 3
SIN CONCATENAR alias (SI me sirve el resultado)
Código SQL:
Ver originalCREATE OR REPLACE FUNCTION prueba(idTaller INTEGER,IN alias VARCHAR(255),OUT VehiculosTaller BIGINT,OUT CapacidadTaller SMALLINT) RETURNS SETOF RECORD AS $BODY$
DECLARE
use_sql TEXT;
BEGIN
use_sql := 'select count(VEHICULOS.id_vehiculo)as VehiculosTaller,locales.capacidad_instalada as CapacidadTaller from SINIESTROS,COMPANIAS,VEHICULOS,LOCALES,TALLERES
where SINIESTROS.id_compania = COMPANIAS.id_compania and SINIESTROS.id_vehiculo = VEHICULOS.id_vehiculo and VEHICULOS.id_estado <> 12 and
VEHICULOS.id_local = LOCALES.id_local and LOCALES.id_taller = TALLERES.id_taller and TALLERES.id_taller = '||idTaller||' and
COMPANIAS.alias = upper(''bci'')group by locales.capacidad_instalada UNION ALL
select count(VEHICULOS.id_vehiculo),locales.capacidad_instalada from SINIESTROS,COMPANIAS,VEHICULOS,LOCALES,TALLERES
where SINIESTROS.id_compania = COMPANIAS.id_compania and SINIESTROS.id_vehiculo = VEHICULOS.id_vehiculo and VEHICULOS.id_estado <> 12 and
VEHICULOS.id_local = LOCALES.id_local and LOCALES.id_taller = TALLERES.id_taller and TALLERES.id_taller = '||idTaller||' and COMPANIAS.alias <> upper(''bci'')
group by locales.capacidad_instalada';
RETURN QUERY EXECUTE use_sql;
END;
$BODY$
LANGUAGE plpgsql;
SELECT * FROM prueba (5,'bci');
VehiculosTaller CapacidadTaller
--------------------- ---------------------------
2 30
1 30