Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using always encrypted and couldn't use IsNull or LEN function. I want to use case and IS NULL or IS NOT NULL to achieve that.

Can someone let me know how to re-write the below logic using CASE and IS NULL/ IS NOT NULL?

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

Update 2 :

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

Then 'E' else 'N' End
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
284 views
Welcome To Ask or Share your Answers For Others

1 Answer

I would write this as:

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

but you probably have the same problem. So the answer to your question using case and is null is:

(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

I don't like case statements in the where clause, so the better answer is the simpler expression:

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

This is really the right way to express the logic.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...