Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
735 B
2
Indexable
Never
CREATE OR REPLACE FUNCTION conam.get_spese_legali(id_fascicolo_in integer)
 RETURNS text
 LANGUAGE plpgsql
AS $function$
DECLARE
spese character varying(45);
BEGIN
	select spese_legali.spese into spese from (( SELECT sen_sa.id, sen_sa.spese
          FROM doc_in_sentenza sen_sa
           JOIN fascicolo_documenti fd_1 ON sen_sa.id_documento = fd_1.id_documento
        WHERE fd_1.id_fascicolo = id_fascicolo_in
      UNION
       SELECT sen_rc.id, sen_rc.spese
        FROM doc_in_sentenza_rc sen_rc
         JOIN fascicolo_documenti fd_1 ON sen_rc.id_documento = fd_1.id_documento
      WHERE fd_1.id_fascicolo = id_fascicolo_in)) as spese_legali
	  order by id desc limit 1;
	  return spese;
END;
$function$
;