2014-06-27 57 views
2

當n.ownerid爲null,它永遠不會執行此部分:在選擇案例爲NULL檢查

...........,case n.ownerid 
    when NULL then 
    (
    select systemuserid 
    from crm_systemuserbase 
    where firstname = 'CRM' and lastname='Admin' 
)........... 

這裏的多個周邊代碼:

,case n.ownerid 
    when NULL then 
    (
    select systemuserid 
    from crm_systemuserbase 
    where firstname = 'CRM' and lastname='Admin' 
    ) 
    when '6e99ff04-f498-e311-93f3-005056a37b31' then 
    (
    select systemuserid 
    from crm_systemuserbase 
    where firstname = 'CRM' and lastname='Admin' 
    ) 
    end as OwnerID 

在SELECT CASE怎麼做一個檢查字段問題的值是否爲空?

回答

7

比較null

case when n.ownerid is null then ... 
    when n.ownerid = '6e99ff04-f498-e311-93f3-005056a37b31' then ... 
end as OwnerID 
+1

可能是值得指出的是,這意味着你已經從轉一個簡單的CASE到搜索到的CASE表達式 –

2

時使用is操作符,你也可以使用COALESCE表達:

CASE when COALESCE(n.ownerid, '(nullVal)') = '(nullVal)' . . .