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.
149 lines
3.7 KiB
149 lines
3.7 KiB
--Freemarker Template |
|
<#include "SQL_lingua_franca"/> |
|
<#include "SuperX_general"/> |
|
-- |
|
--Autor D. Quathamer 2024 |
|
<sqlvars> |
|
<sqlvar name="column_layouts" type="hashsequence"><![CDATA[ |
|
select L.tid, |
|
L.uniquename, |
|
L.caption, |
|
L.whereclause, |
|
L.uniquename as target_tablename, |
|
R.uniquename as resultset_uniquename, |
|
'tmp_' || R.uniquename as resultset_tablename, |
|
R.fieldclause as resultset_fieldclause, |
|
R.joinclause as resultset_joinclause, |
|
R.whereclause as resultset_whereclause, |
|
R.systeminfo_id as resultset_systeminfo_id |
|
from rpta_resultset R, rpta_column_layout L |
|
where L.resultset_id=R.tid |
|
and L.is_virtual=0 |
|
]]> |
|
</sqlvar> |
|
|
|
<sqlvar name="columns" type="hashsequence"><![CDATA[ |
|
SELECT L.tid as layout_id, |
|
C.srcfieldname, |
|
(case when string_not_null(C.targetfieldname)='' then C.srcfieldname else C.targetfieldname end) as targetfieldname, |
|
T.uniquename as coltype, |
|
C.is_aggregate, |
|
(case when string_not_null(CL.caption)='' then C.caption else CL.caption end) as caption, |
|
CL.is_visible, |
|
CL.visible_size as visible_width, |
|
(select F.sql_code from rpta_format_code F where F.tid=CL.format_code_id) as format_sql, |
|
C.col_function as colfunction, |
|
(case when string_not_null(CL.description)='' then C.description else CL.description end) as description |
|
FROM rpta_column_layout L, rpta_column2layout CL, rpta_column C, rpta_column_type T |
|
where L.tid=CL.layout_id |
|
and C.tid=CL.column_id |
|
and T.tid=C.column_type |
|
and L.is_virtual=0 |
|
order by CL.sortnr |
|
; |
|
]]></sqlvar> |
|
|
|
</sqlvars> |
|
|
|
<#if column_layouts?has_content> |
|
|
|
<#foreach column_layout in column_layouts> |
|
|
|
<#if columns?has_content> |
|
|
|
--zuerst resultset aufbauen: |
|
create temp table ${column_layout.resultset_tablename} as |
|
select ${column_layout.resultset_fieldclause} |
|
from ${column_layout.resultset_joinclause} |
|
where 1=1 |
|
<#if column_layout.resultset_whereclause != ""> |
|
${column_layout.resultset_whereclause} </#if> |
|
; |
|
|
|
--dann das Spaltenlayout |
|
select |
|
--zuerst die Basisdaten: |
|
<#foreach column in columns> |
|
<#if column.layout_id=column_layout.tid> |
|
|
|
<#if column.coltype="physicalColumn"> |
|
${column.srcfieldname}, |
|
<#elseif column.coltype="logicalColumn"> |
|
${column.colfunction} as ${column.targetfieldname}, |
|
<#elseif column.coltype="lookupColumn"> |
|
(${column.colfunction}) as ${column.targetfieldname}, |
|
<#elseif column.coltype="computedColumn"> |
|
null::decimal(19,6) as ${column.targetfieldname}, |
|
</#if> |
|
|
|
</#if> |
|
</#foreach> |
|
null::char(1) as dummycol |
|
into temp tmp_stud |
|
from ${column_layout.resultset_tablename} |
|
where 1=1 |
|
<#if column_layout.whereclause !=""> |
|
and ${column_layout.whereclause} |
|
</#if> |
|
; |
|
|
|
drop table if exists ${column_layout.target_tablename} ; |
|
|
|
<#assign index_clause="" /> |
|
|
|
--ergebnistabelle: |
|
create table ${column_layout.target_tablename} as select |
|
--zuerst die nicht-Aggregate: |
|
<#assign groupby=0 /> |
|
<#foreach column in columns> |
|
<#if column.layout_id=column_layout.tid> |
|
|
|
<#if column.is_aggregate==0> |
|
<#assign groupby=groupby+1 /> |
|
${column.targetfieldname}, |
|
|
|
<#assign index_clause=index_clause+ " |
|
create index ix_${column_layout.target_tablename}_${groupby} on ${column_layout.target_tablename}(${column.targetfieldname});" /> |
|
</#if> |
|
|
|
|
|
|
|
|
|
</#if> |
|
</#foreach> |
|
--dann die Aggregate: |
|
<#foreach column in columns> |
|
<#if column.layout_id=column_layout.tid> |
|
|
|
<#if column.is_aggregate==1 && column.coltype!="computedColumn"> |
|
sum(${column.targetfieldname}) as ${column.targetfieldname}, |
|
</#if> |
|
|
|
</#if> |
|
</#foreach> |
|
null::char(1) as dummycol |
|
from tmp_stud |
|
where 1=1 |
|
<#if groupby !=0 > |
|
group by |
|
<#list 1..groupby as i>${i} |
|
<#if i != groupby> |
|
, |
|
</#if> |
|
</#list> |
|
</#if> |
|
|
|
; |
|
|
|
${index_clause} |
|
|
|
|
|
drop table if exists tmp_stud; |
|
drop table if exists tmp_gesamt; |
|
|
|
|
|
</#if> --wenn columns?has_content |
|
drop table ${column_layout.resultset_tablename}; |
|
</#foreach> -- Ende Schleife column_layouts |
|
</#if> --gibt es column_layouts |
|
|
|
|