1

Does Invantive SQL support multiple condition in a single case statement? I the statement below, I did not get any results. Tried the same statement with only 1 condition (no cascade), this retrieved the expected result.

   select prj.code
   ,      prj.startdate
   ,      prj.enddate
   from   exactonlinerest..projects prj
   where  prj.code between $P{P_PROJECT_FROM} and $P{P_PROJECT_TO}
   and    case
   /*       when (prj.enddate is null or prj.enddate >= sysdate)
          then 'Y'   
          when (prj.enddate is not null and prj.enddate <= sysdate)
          then 'N'   */
          when prj.startdate <= sysdate  
          then 'B'  
          end 
          = $P{P_PROJECT_ACTIVE_FROM} 
4

1 回答 1

0

我认为您的 where 子句表述不正确。使用 Exact Online,项目要么具有:

  • 选项 1:没有结束日期,
  • 选项 2:过去的结束日期
  • 选项 3:或未来的结束日期

第一部分case处理选项 1 和选项 3。第二部分处理选项 2。所以'B'在这种情况下永远不会有结果。

要分析此类问题,我建议case在 select 子句中包含 并删除过滤器。这使您可以了解可能的结果。

例子:

use 868056,102673

select prj.division
,      prj.code
,      prj.startdate
,      prj.enddate
,      case
       when prj.enddate is null or prj.enddate >= sysdate
       then 'Y'   
       when prj.enddate is not null and prj.enddate <= sysdate
       then 'N'   
       when prj.startdate <= sysdate  
       then 'B'  
       end 
       indicator
from   exactonlinerest..projects prj   
where  prj.code between $P{P_PROJECT_FROM} and $P{P_PROJECT_TO}   
于 2016-12-03T11:42:55.867 回答