|
|
src: |
|
|
|
SELECT v_listes_1.liste_id_combo AS oid,
|
|
|
v_listes_1.texte,
|
|
|
''::text AS code,
|
|
|
v_listes_1.lvl AS level,
|
|
|
('0'::text || v_listes_1.sort) || chr(1) AS tri,
|
|
|
CASE
|
|
|
WHEN v_listes_1.is_cti = '1'::text OR v_listes_1.code ~~ 'CTI_%'::text THEN '1'::character(1)
|
|
|
ELSE '0'::character(1)
|
|
|
END AS is_cti
|
|
|
FROM base.v_listes_1
|
|
|
WHERE v_listes_1.table_code = 'LPP'::text AND v_listes_1.lvl <> '0'::text
|
|
|
UNION ALL
|
|
|
SELECT ('LC'::text || lpad(t_classes.sequence::text, 2, '0'::text)) || t_classes.oid::text AS oid,
|
|
|
t_classes.texte,
|
|
|
''::text AS code,
|
|
|
'1'::text AS level,
|
|
|
'5'::text || btrim(rpad(lpad(t_classes.sequence::text, 2, '0'::text), 10, ' '::text)) AS tri,
|
|
|
CASE
|
|
|
WHEN t_classes.is_cti = '1'::bpchar OR t_classes.code ~~ 'CTI_%'::text THEN '1'::character(1)
|
|
|
ELSE '0'::character(1)
|
|
|
END AS is_cti
|
|
|
FROM base.t_classes,
|
|
|
base.t_listes_tables
|
|
|
WHERE t_classes.table_id = t_listes_tables.oid AND t_listes_tables.code = 'LPP'::text
|
|
|
UNION ALL
|
|
|
SELECT ('LS'::text || lpad(t_classes.sequence::text, 2, '0'::text)) || t_classes_sections.oid::text AS oid,
|
|
|
t_classes_sections.texte,
|
|
|
''::text AS code,
|
|
|
'2'::text AS level,
|
|
|
'5'::text || btrim(rpad(lpad(t_classes.sequence::text, 2, '0'::text), 10, ' '::text) || t_classes_sections.code) AS tri,
|
|
|
CASE
|
|
|
WHEN t_classes.is_cti = '1'::bpchar OR t_classes.code ~~ 'CTI_%'::text THEN '1'::character(1)
|
|
|
ELSE '0'::character(1)
|
|
|
END AS is_cti
|
|
|
FROM base.t_classes,
|
|
|
base.t_classes_sections,
|
|
|
base.t_listes_tables
|
|
|
WHERE t_classes.table_id = t_listes_tables.oid AND t_classes_sections.classe_id = t_classes.oid AND t_listes_tables.code = 'LPP'::text
|
|
|
UNION ALL
|
|
|
SELECT ('LS'::text || lpad(t_classes.sequence::text, 2, '0'::text)) || '0'::text AS oid,
|
|
|
'Section non attribuée'::character varying AS texte,
|
|
|
''::text AS code,
|
|
|
'2'::text AS level,
|
|
|
'5'::text || btrim(rpad(lpad(t_classes.sequence::text, 2, '0'::text), 10, ' '::text) || chr(255)) AS tri,
|
|
|
CASE
|
|
|
WHEN t_classes.is_cti = '1'::bpchar OR t_classes.code ~~ 'CTI_%'::text THEN '1'::character(1)
|
|
|
ELSE '0'::character(1)
|
|
|
END AS is_cti
|
|
|
FROM base.t_classes,
|
|
|
base.t_listes_tables
|
|
|
WHERE t_classes.table_id = t_listes_tables.oid AND t_listes_tables.code = 'LPP'::text
|
|
|
UNION ALL
|
|
|
SELECT 'D1'::text || t_lpp_c.classification_atc_1_id::text AS oid,
|
|
|
max((t_lpp_c.classification_atc_1_code::text || ' '::text) || t_lpp_c.classification_atc_1_texte::text) AS texte,
|
|
|
''::text AS code,
|
|
|
'1'::text AS level,
|
|
|
max('6'::text || rpad(t_lpp_c.classification_atc_1_code::text, 10, ' '::text)) AS tri,
|
|
|
'0'::bpchar AS is_cti
|
|
|
FROM activite.t_lpp_c
|
|
|
WHERE t_lpp_c.classification_atc_id <> 0 AND (t_lpp_c.oid IN ( SELECT p_oids.oid
|
|
|
FROM activite.p_oids
|
|
|
WHERE p_oids.code_table = 'lpp'::text))
|
|
|
GROUP BY ('D1'::text || t_lpp_c.classification_atc_1_id::text)
|
|
|
UNION ALL
|
|
|
SELECT 'D2'::text || t_lpp_c.classification_atc_2_id::text AS oid,
|
|
|
max((t_lpp_c.classification_atc_2_code::text || ' '::text) || t_lpp_c.classification_atc_2_texte::text) AS texte,
|
|
|
''::text AS code,
|
|
|
'2'::text AS level,
|
|
|
max(('6'::text || rpad(t_lpp_c.classification_atc_1_code::text, 10, ' '::text)) || rpad(t_lpp_c.classification_atc_2_code::text, 10, ' '::text)) AS tri,
|
|
|
'0'::bpchar AS is_cti
|
|
|
FROM activite.t_lpp_c
|
|
|
WHERE t_lpp_c.classification_atc_id <> 0 AND (t_lpp_c.oid IN ( SELECT p_oids.oid
|
|
|
FROM activite.p_oids
|
|
|
WHERE p_oids.code_table = 'lpp'::text))
|
|
|
GROUP BY ('D2'::text || t_lpp_c.classification_atc_2_id::text)
|
|
|
UNION ALL
|
|
|
SELECT 'D3'::text || t_lpp_c.classification_atc_3_id::text AS oid,
|
|
|
max((t_lpp_c.classification_atc_3_code::text || ' '::text) || t_lpp_c.classification_atc_3_texte::text) AS texte,
|
|
|
''::text AS code,
|
|
|
'3'::text AS level,
|
|
|
max((('6'::text || rpad(t_lpp_c.classification_atc_1_code::text, 10, ' '::text)) || rpad(t_lpp_c.classification_atc_2_code::text, 10, ' '::text)) || rpad(t_lpp_c.classification_atc_3_code::text, 10, ' '::text)) AS tri,
|
|
|
'0'::bpchar AS is_cti
|
|
|
FROM activite.t_lpp_c
|
|
|
WHERE t_lpp_c.classification_atc_id <> 0 AND (t_lpp_c.oid IN ( SELECT p_oids.oid
|
|
|
FROM activite.p_oids
|
|
|
WHERE p_oids.code_table = 'lpp'::text))
|
|
|
GROUP BY ('D3'::text || t_lpp_c.classification_atc_3_id::text)
|
|
|
UNION ALL
|
|
|
SELECT 'D4'::text || t_lpp_c.classification_atc_4_id::text AS oid,
|
|
|
max((t_lpp_c.classification_atc_4_code::text || ' '::text) || t_lpp_c.classification_atc_4_texte::text) AS texte,
|
|
|
''::text AS code,
|
|
|
'4'::text AS level,
|
|
|
max(((('6'::text || rpad(t_lpp_c.classification_atc_1_code::text, 10, ' '::text)) || rpad(t_lpp_c.classification_atc_2_code::text, 10, ' '::text)) || rpad(t_lpp_c.classification_atc_3_code::text, 10, ' '::text)) || rpad(t_lpp_c.classification_atc_4_code::text, 10, ' '::text)) AS tri,
|
|
|
'0'::bpchar AS is_cti
|
|
|
FROM activite.t_lpp_c
|
|
|
WHERE t_lpp_c.classification_atc_id <> 0 AND (t_lpp_c.oid IN ( SELECT p_oids.oid
|
|
|
FROM activite.p_oids
|
|
|
WHERE p_oids.code_table = 'lpp'::text))
|
|
|
GROUP BY ('D4'::text || t_lpp_c.classification_atc_4_id::text)
|
|
|
UNION ALL
|
|
|
SELECT 'D5'::text || t_lpp_c.classification_atc_id::text AS oid,
|
|
|
max((t_lpp_c.classification_atc_code::text || ' '::text) || t_lpp_c.classification_atc_texte::text) AS texte,
|
|
|
''::text AS code,
|
|
|
'5'::text AS level,
|
|
|
max((((('6'::text || rpad(t_lpp_c.classification_atc_1_code::text, 10, ' '::text)) || rpad(t_lpp_c.classification_atc_2_code::text, 10, ' '::text)) || rpad(t_lpp_c.classification_atc_3_code::text, 10, ' '::text)) || rpad(t_lpp_c.classification_atc_4_code::text, 10, ' '::text)) || rpad(t_lpp_c.classification_atc_code::text, 10, ' '::text)) AS tri,
|
|
|
'0'::bpchar AS is_cti
|
|
|
FROM activite.t_lpp_c
|
|
|
WHERE t_lpp_c.classification_atc_id <> 0 AND (t_lpp_c.oid IN ( SELECT p_oids.oid
|
|
|
FROM activite.p_oids
|
|
|
WHERE p_oids.code_table = 'lpp'::text))
|
|
|
GROUP BY ('D5'::text || t_lpp_c.classification_atc_id::text)
|
|
|
UNION ALL
|
|
|
SELECT 'DT'::text || t_lpp_c.oid::text AS oid,
|
|
|
(t_lpp_c.code || ' '::text) || t_lpp_c.texte_court AS texte,
|
|
|
t_lpp_c.code,
|
|
|
'1'::text AS level,
|
|
|
'9'::text || t_lpp_c.code AS tri,
|
|
|
'0'::character(1) AS is_cti
|
|
|
FROM activite.t_lpp_c
|
|
|
WHERE (t_lpp_c.oid IN ( SELECT p_oids.oid
|
|
|
FROM activite.p_oids
|
|
|
WHERE p_oids.code_table = 'lpp'::text))
|
|
|
ORDER BY 5;
|