I have a long nested full outer join sequence I need to implement in Sybase Adaptive Server Enterprise. Is it possible to write a function for this?
I want to simplify the code below:
select t1.col_01, t1.col_02, TOT_Jan, TOT_Feb
from
(select a.col_01, a.col_02, sum(b.col_XX) as TOT_Jan
FROM vw_aux a ...
and year(b.tms_mydate) = 2012
and month(b.tms_mydate) = 1
... ) t1
left outer join
(select a.col_01, a.col_02, sum(b.col_XX) as TOT_Feb
... and year(b.tms_mydate) = 2012
and month(b.tms_mydate) = 2
... ) t2 on t1.col_aux = t2.col_aux
UNION
(select a.col_01, a.col_02, sum(b.col_XX) as TOT_Jan ...) t1
right outer join (select a.col_01, a.col_02, sum(b.col_XX) as TOT_Feb ...) t2
on ...
Creating a function like this:
funcion myfullouterjoin (vw_aux, table_01, col_aux, col_01, col_02, tms_mydate, TOT_Jan, TOT_Feb)