我的表cust_shipmentdate_awb和comp_shipdate_awb中有两个字段。我试图写一个CASE语句,它应该检查两个字段cust_shipmentdate_awb和comp_shipdate_awb是null还是空。如果两者都为空,则将结果显示为“待定”。如果任何一个字段不为空,则它应显示为“已完成”。如果同时输入两个字段,则它应显示为“已完成”。我已经尝试过以下CASE声明。但是当输入两个字段数据时它显示为挂起。我试图按照以下数据来实现。
============================================================
cust_shipmentdate_awb | comp_shipdate_awb | shipment_status
============================================================
02-03-2016 | | Completed
| 09-08-2016 | Completed
NULL | NULL | Pending
01-06-2016 | 09-08-2016 | Completed
============================================================
CASE
When cust_shipmentdate_awb Is Null Or comp_shipdate_awb = '' Then 'Pending'
Else 'Completed' End AS shipment_status
答案 0 :(得分:1)
尝试使用AND
运算符,并检查两个字段是否为null和空(''):
CASE
When (cust_shipmentdate_awb Is Null OR cust_shipmentdate_awb = '')
AND (comp_shipdate_awb Is Null OR comp_shipdate_awb = '') Then 'Pending'
Else 'Completed' End AS shipment_status