0

我有一个需要在 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)
4

1 回答 1

0

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

您可以查看 Sybase 文档:函数存储过程

于 2013-03-20T19:55:08.797 回答