[英]Replacing IsNull and LEN with Case and IS NULL
我使用的始終是加密的,無法使用IsNull或LEN函數。 我想使用case和IS NULL或IS NOT NULL來實現這一點。
有人可以讓我知道如何使用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
我可以這樣寫:
len(coalesce(c.email1, e.email, org_email)) <> 0
但您可能有同樣的問題。 因此,使用case
且is 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)
這確實是表達邏輯的正確方法。
這是你想要的嗎 ? 如果您需要電子郵件:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.