Syntax error “Missing keyword” in case statement in WHERE clause

后端 未结 3 1210
感动是毒
感动是毒 2021-01-26 13:31

I am having some syntax error in my case statement where I am checking below condition:

((RAP10B.CLMSRC = \'2\', RAP01.EFFDT - 3 years <= RAP10.LOSSDT < RA         


        
相关标签:
3条回答
  • 2021-01-26 14:09

    It's generally much better to use AND/OR constructions in the WHERE clause instead of case expressions:

    WHERE (RAP10B.CLMSRC = '2'
           AND rap10.lossdt_t BETWEEN Add_months(rap01.teffdt_t, - 36) AND rap01.teffdt_t)
       OR (RAP10B.CLMSRC <> '2'
           AND rap10.lossdt_t BETWEEN Add_months(rap01.teffdt_t, - 36) AND (rap01.teffdt_t - 60))
    
    0 讨论(0)
  • 2021-01-26 14:11

    Try below -

    CASE
      WHEN RAP10B.CLMSRC = '2'
      and rap10.lossdt_t BETWEEN Add_months(rap01.teffdt_t, - 36) AND rap01.teffdt_t then yourval
      WHEN RAP10B.CLMSRC <> '2'
      and rap10.lossdt_t BETWEEN Add_months(rap01.teffdt_t, - 36) AND (rap01.teffdt_t - 60) yourval1
    END 
    
    0 讨论(0)
  • 2021-01-26 14:12

    Are you looking for something like this?

    CASE
       WHEN RAP10B.CLMSRC = '2'
          AND rap10.lossdt_t BETWEEN Add_months(rap01.teffdt_t, - 36) 
          AND rap01.teffdt_t THEN <your_column>
       WHEN RAP10B.CLMSRC <> '2'
          AND rap10.lossdt_t BETWEEN Add_months(rap01.teffdt_t, - 36) 
          AND (rap01.teffdt_t - 60) THEN <your_column>
    END 
    
    0 讨论(0)
提交回复
热议问题