Ok, in this case it is too big to transform it into a SQL UDF.
You facing here the problem of an de-normalized design which leads to komplex queries.
CREATE MULTISET TABLE DB_TEST.T1
(
A DECIMAL(15,0),
B DECIMAL(15,0),
column_position byteint,
JOINkey INTEGER,
NO INTEGER
insert_dt DATE FORMAT 'YY/MM/DD')
PRIMARY INDEX ( A );
(where column_position (e.g. 1 to 4 based on your odering) would only be needed if it has a real meaning for you)
would be a straight forward input for your mapping as you could straight forward join the two tables.
If afterwards a de-normalized presentation of the data would be required you could "aggregate" the data by doing
Seletc t1.a,
t1.b,
max(case when column_position = 1 then t2.newfiled else null end) as nf1,
max(case when column_position = 2 then t2.newfiled else null end) as nf2,
max(case when column_position = 3 then t2.newfiled else null end) as nf3,
max(case when column_position = 4 then t2.newfiled else null end) as nf4
from t1
left outer join
t2
on t1.joinkey = t2.a
and t2.no = t2.b
group by t1.a,
t2.a
;
Still not most elegant SQL but performance wise it should be much more efficient then doing so many left outer joins.
Ok, in this case it is too big to transform it into a SQL UDF.
You facing here the problem of an de-normalized design which leads to komplex queries.
(where column_position (e.g. 1 to 4 based on your odering) would only be needed if it has a real meaning for you)
would be a straight forward input for your mapping as you could straight forward join the two tables.
If afterwards a de-normalized presentation of the data would be required you could "aggregate" the data by doing
Still not most elegant SQL but performance wise it should be much more efficient then doing so many left outer joins.