创建一个在Sybase中实现完全外连接的函数

时间:2013-03-18 22:16:58

标签: user-defined-functions sybase-ase outer-join

我有一个需要在Sybase Adaptive Server Enterprise中实现的长嵌套全外连接序列。是否可以为此编写函数?

我想简化以下代码:

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 ...

创建这样的函数:

funcion myfullouterjoin (vw_aux, table_01, col_aux, col_01, col_02, tms_mydate, TOT_Jan, TOT_Feb)

1 个答案:

答案 0 :(得分:0)

函数没有输出参数,因此,您无法在那里实现查询 但是,在我看来,存储过程或视图完全符合您的需求。

您可以查看Sybase文档:FunctionsStored Procedures