exact-onlineinvantive-sqlinvantive-controlinvantive-query-tool

Combining multiple condition in single case statement


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} 

Solution

  • I think you where clause is not correctly formulated. With Exact Online, a project either has:

    The first part of the case handles option 1 and option 3. The second part handles option 2. So there is never an outcome of 'B' in the case.

    To analyze such problems, I recommend include the case in the select clause and removing the filter. That gives you a view of the possible outcomes.

    Example:

    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}