You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

36 lines
1.1 KiB

return: text
lang: plpgsql
parameters:
p0:
type: integer
name: input_rapport_id
p1:
type: text
name: select_name
strict: STRICT
src: |
DECLARE
rapport_columns TEXT;
rapports_cursor refcursor;
numero_rubrique INTEGER;
table_name TEXT;
BEGIN
rapport_columns = 'CASE';
OPEN rapports_cursor FOR
SELECT t_rapports_rubriques.numero_rubrique, t_indicateurs.table_name
FROM activite.t_rapports_rubriques, activite.t_indicateurs
WHERE rapport_id = $1 AND indicateur_id = t_indicateurs.oid
ORDER BY t_rapports_rubriques.numero_rubrique;
FETCH rapports_cursor INTO numero_rubrique, table_name;
WHILE FOUND LOOP
IF (table_name != 'SEP') THEN
rapport_columns = rapport_columns || ' WHEN t_rapports_rubriques.numero_rubrique = ' || numero_rubrique || ' THEN ' || $2 || '.indicateur' || numero_rubrique;
END IF;
FETCH rapports_cursor INTO numero_rubrique, table_name ;
END LOOP;
CLOSE rapports_cursor;
rapport_columns = rapport_columns || ' ELSE 0 END';
RETURN rapport_columns ;
END;