2016-08-03 45 views
-1

我使用的是始終加密的,無法使用IsNull或LEN函數。我想用case和IS NULL或IS NOT NULL來實現這一點。用大小寫替換IsNull和LEN並且爲空

有人可以讓我知道如何重寫下面的邏輯使用CASE和IS NULL/IS NOT NULL嗎?

Len(IsNull(c.email1, IsNull(e.email,ORG_Email))) <> 0 

更新2:

case when email_indicator != 'N' and Len(IsNull(c.email1, IsNull(e.email,ORG_Email))) <> 0 

Then 'E' else 'N' End 

回答

3

我會寫爲:

len(coalesce(c.email1, e.email, org_email)) <> 0 

但你可能有同樣的問題。所以答案使用caseis null你的問題是:

(case when c.email1 is null and e.email is null and org_email is null 
     then 0 -- all are missing 
     else 1 
end) = 1 

我不喜歡where子句中case語句,所以更好的答案是簡單的表達:

(c.email1 is not null or e.email is not null or org_email is not null) 

這是真的表達邏輯的正確方式。

+0

在你的第二個答案,如果有什麼其中一封電子郵件不爲空? – HadoopAddict

+0

我已經添加了該問題的更新。我真的想要實現這一點。 – HadoopAddict

0

這是你想要的嗎? 如果你想要的電子郵件:

case when c.email1 is not null then c.email1 
    when e.email is not null then c.email 
    else ORG_Email end 

如果你想要的是,以確定是否電子郵件存在:

case when c.email1 is not null then 1 
    when e.email is not null then 1 
    when ORG_Email is not null then 1 else 0 end 

或合併的情況下

case when c.email1 is not null Or e.email is not null Or 
      ORG_Email is not null then 1 else 0 end 
+0

我已經添加了該問題的更新。我真的想要實現這一點 – HadoopAddict

相關問題