|
4 | 4 |
|
5 | 5 | DROP TABLE IF EXISTS v_ahbtabellen; -- this is because sqlmodel tries to create a table first... it doesn't know that this is just a view. bit dirty but ok.
|
6 | 6 | DROP VIEW IF EXISTS v_ahbtabellen;
|
7 |
| -CREATE VIEW v_ahbtabellen as |
8 |
| -SELECT id as id, |
9 |
| - edifact_format_version as format_version, |
10 |
| - pruefidentifikator as pruefidentifikator, |
11 |
| - path, |
12 |
| - id_path, |
13 |
| - kommunikation_von as direction, |
14 |
| - beschreibung as description, |
15 |
| - 'SG' || segmentgroup_id as segmentgroup_key, -- eg 'SG6' |
16 |
| - segment_id as segment_code, -- e.g 'NAD' |
17 |
| - dataelement_id as data_element, -- e.g 'D_3035' |
| 7 | + |
| 8 | +CREATE VIEW v_ahbtabellen AS |
| 9 | +WITH consolidated_ahm AS (SELECT id, |
| 10 | + edifact_format_version, |
| 11 | + format, |
| 12 | + pruefidentifikator, |
| 13 | + path, |
| 14 | + id_path, |
| 15 | + kommunikation_von, |
| 16 | + beschreibung, |
| 17 | + segmentgroup_id, |
| 18 | + segment_id, |
| 19 | + dataelement_id, |
| 20 | + code_value, |
| 21 | + sort_path, |
| 22 | + trim(coalesce(code_ahb_status, coalesce(dataelement_ahb_status, |
| 23 | + coalesce(segment_ahb_status, segmentgroup_ahb_status)))) AS line_ahb_status, |
| 24 | + coalesce(code_name, coalesce(dataelement_name, coalesce(dataelementgroup_name, |
| 25 | + coalesce(segment_name, segmentgroup_name)))) AS line_name |
| 26 | + FROM ahb_hierarchy_materialized ahm |
| 27 | + WHERE ahm.TYPE != 'dataelementgroup' |
| 28 | + AND (ahm.TYPE != 'dataelement' OR ahm.dataelement_ahb_status IS NOT NULL)) |
| 29 | + |
| 30 | +SELECT c.id as id, |
| 31 | + c.edifact_format_version as format_version, |
| 32 | + c.format as format, |
| 33 | + c.pruefidentifikator as pruefidentifikator, |
| 34 | + c.path, |
| 35 | + c.id_path, |
| 36 | + c.kommunikation_von as direction, |
| 37 | + c.beschreibung as description, |
| 38 | + 'SG' || c.segmentgroup_id as segmentgroup_key, -- eg 'SG6' |
| 39 | + c.segment_id as segment_code, -- e.g 'NAD' |
| 40 | + c.dataelement_id as data_element, -- e.g 'D_3035' |
18 | 41 | --CASE
|
19 | 42 | -- WHEN dataelement_id IS NOT NULL THEN SUBSTR(dataelement_id, 3)
|
20 | 43 | -- END AS dataelement_without_leading_d_, -- e.g '3035'
|
21 |
| - code_value as qualifier, |
| 44 | + c.code_value as qualifier, |
| 45 | + c.line_ahb_status as line_ahb_status, -- e.g. 'Muss [28] ∧ [64]' |
| 46 | + c.line_name as line_name, -- e.g. 'Datums- oder Uhrzeit- oder Zeitspannen-Format, Code' or 'Produkt-Daten für Lieferant relevant' |
| 47 | + c.sort_path as sort_path, |
| 48 | + NULLIF(ahe.node_texts, '') as bedingung, |
| 49 | + NULLIF(ahe.ahbicht_error_message, '') as bedingungsfehler |
| 50 | +FROM consolidated_ahm as c |
| 51 | + LEFT JOIN ahb_expressions as ahe -- if this table is missing, call create_and_fill_ahb_expression_table(...) first |
| 52 | + ON ahe.edifact_format_version = c.edifact_format_version |
| 53 | + AND ahe.format = c.format |
| 54 | + AND ahe.expression = c.line_ahb_status; |
| 55 | + |
22 | 56 |
|
23 |
| - coalesce(code_ahb_status, coalesce(dataelement_ahb_status, |
24 |
| - coalesce(segment_ahb_status, segmentgroup_ahb_status))) as line_ahb_status, -- e.g. 'Muss [28] ∧ [64]' |
25 |
| - coalesce(code_name, coalesce(dataelement_name, coalesce(dataelementgroup_name, |
26 |
| - coalesce(segment_name, segmentgroup_name)))) as line_name, -- e.g. 'Datums- oder Uhrzeit- oder Zeitspannen-Format, Code' or 'Produkt-Daten für Lieferant relevant' |
27 |
| - sort_path as sort_path |
28 |
| --- the bedingung column is still missing, but we'll solve this one separately |
29 |
| -FROM ahb_hierarchy_materialized |
30 |
| -WHERE TYPE != 'dataelementgroup' AND (TYPE != 'dataelement' OR dataelement_ahb_status IS NOT Null) ; |
|
0 commit comments