>>>>Ok... presumindo que vc queira que sejam *todas as empresas* quando o "$1 
>>>>IS NULL", ou seja, o primeiro parâmetro seja nulo, então vc pode fazer o 
>>>>seguinte:
>>>>
>>>>
>>>>
>>>>
>>>>r_lista RECORD;
>>>>t_sql TEXT;
>>>>
>>>>BEGIN
>>>>
>>>>  t_sql := 'SELECT codigo, nome FROM tcliente WHERE ativo = 1';
>>>>  t_sql := t_sql || COALESCE(' AND empresa = ' || $1, '');
>>>>
>>>>  FOR r_lista IN EXECUTE t_sql LOOP
>>>>
>>>>
>>>Funcionou.
>>>
>>
...
select codigo, nome from tcliente where ativo = 1 and empresa between 
coalesce($1,0) and coalesce($1,999)

...

Jean Domingues
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a