How to improve a case statement that uses two columns

后端 未结 2 1150
南笙
南笙 2021-02-12 01:54

I have a table called Purchase which has a State column, where 1 is authorized, 2 is completed (there are some other values too).

I also have a Retailer table, which has

2条回答
  •  眼角桃花
    2021-02-12 02:16

    Just change your syntax ever so slightly:

    CASE WHEN STATE = 2 AND RetailerProcessType = 1 THEN '"AUTHORISED"'
         WHEN STATE = 1 AND RetailerProcessType = 2 THEN '"PENDING"'
         WHEN STATE = 2 AND RetailerProcessType = 2 THEN '"AUTHORISED"'
         ELSE '"DECLINED"'
    END
    

    If you don't put the field expression before the CASE statement, you can put pretty much any fields and comparisons in there that you want. It's a more flexible method but has slightly more verbose syntax.

提交回复
热议问题