Blank results from one column based on status of another column

I have a table that feeds a website and I want to only display the email address that  don't have the NOTDSPLY flag set to -1. I do want the rest of the data to display, basically I want to blank out the email address where  NOTDSPLY = -1 I tried  CASE WHEN NOTDSPLY =-1 THEN EMAIL = '' ELSE EMAIL END AS EMAIL but that didn't work
SELECT        TOP (100) PERCENT STOCKING_DEALER_NAME, ADDRESS1, ADDRESS2, CITY, STATE, ZIP, PHONE_NO, LOWER(EMAIL) AS EMAIL, LOWER(ISNULL(MONDAY, 'NA')) 
                         AS MONDAY, LOWER(ISNULL(TUESDAY, 'NA')) AS TUESDAY, LOWER(ISNULL(WEDNESDAY, 'NA')) AS WEDNESDAY, LOWER(ISNULL(THURSDAY, 'NA')) 
                         AS THURSDAY, LOWER(ISNULL(FRIDAY, 'NA')) AS FRIDAY, LOWER(ISNULL(SATURDAY, 'NA')) AS SATURDAY, LOWER(ISNULL(SUNDAY, 'NA')) AS SUNDAY, 
                         CREDATE, MODDATE, INACTIVE
FROM            dbo.ATI_STDLR

Open in new window

skull52Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dsackerContract ERP Admin/ConsultantCommented:
Try this:

Change:

LOWER(EMAIL) AS EMAIL
To:

CASE WHEN NOTDSPLY = -1 THEN '' ELSE LOWER(EMAIL) END AS EMAIL
Does that work?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
You're close.  EMAIL='' would attempt to set the value, and all you're trying to do is conditionally display it, so...

CASE WHEN NOTDSPLAY = -1 THEN '' ELSE EMAIL END as EMAIL

btw if it helps I have an article called SQL Server CASE Solutions that's a good read.
0
skull52Author Commented:
Thanks to both of you but dsacker got you by 4 tenths of a sec Jim. Thanks for pointing to your article it was a good read.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.