Trying to use IF/CASE Statement within a Where Clause using BETWEEN in Oracle -


i trying following case statement within clause , it's not working. have searched everywhere , can't find solution. error report says:

pl/sql: ora-00905: missing keyword. 

which keyword missing?

select count(*)     v_sql_count     xaction_level_info b     v_measure_map(i).v_upload_code = b.upload_code     , v_xs_scope(j).v_scope_key        = b.scope     ,       case when     v_measure_map(i).v_date_stamp='benchmark_date'      v_xs_scope(j).v_enriched_date between nvl(b.effective_start_time, 00000000000000) , nvl(b.effective_end_time, 99999999999999)     else     v_xs_scope(j).v_enriched_time between nvl(b.effective_start_time, 00000000000000) , nvl(b.effective_end_time, 99999999999999)      end     , b.level_order =       (select min(level_order)       xaction_level_info       scope                                   = b.scope       , upload_code                               = b.upload_code       , nvl(effective_start_time, 00000000000000) = nvl(b.effective_start_time, 00000000000000)       , nvl(effective_end_time, 99999999999999)   = nvl(b.effective_end_time, 99999999999999)       ) ; 

i tried method it's not giving me results desire. can explain why? oracle seems using v_xs_scope(j).v_enriched_time regardless of whether enriched_date in date_stamp field or not.

    case when     v_measure_map(i).v_date_stamp='enriched_date'      v_xs_scope(j).v_enriched_date     when      v_measure_map(i).v_date_stamp='benchmark_date'      v_xs_scope(j).v_benchmark_date     else     v_xs_scope(j).v_enriched_time      end     between nvl(b.effective_start_time, 00000000000000) , nvl(b.effective_end_time, 99999999999999)  

instead of using case expression, use or expression take both options account.

select count(*) -- match measure value on these keys.         v_sql_count         xaction_level_info b         v_measure_map(i).v_upload_code = b.upload_code         , v_xs_scope(j).v_scope_key        = b.scope         , (                 (                 v_measure_map(i).v_date_stamp='benchmark_date'                 , v_xs_scope(j).v_enriched_date between nvl(b.effective_start_time, 00000000000000) , nvl(b.effective_end_time, 99999999999999)                 )             or                 (                 v_measure_map(i).v_date_stamp<>'benchmark_date'                 , v_xs_scope(j).v_enriched_time between nvl(b.effective_start_time, 00000000000000) , nvl(b.effective_end_time, 99999999999999)                  )             )         , b.level_order =           (select min(level_order)           xaction_level_info           scope                                   = b.scope           , upload_code                               = b.upload_code           , nvl(effective_start_time, 00000000000000) = nvl(b.effective_start_time, 00000000000000)           , nvl(effective_end_time, 99999999999999)   = nvl(b.effective_end_time, 99999999999999)           ) ;   

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -