We help IT Professionals succeed at work.

If a specific result is displayed in a query display null instead

Medium Priority
143 Views
Last Modified: 2012-05-06
I have a simple query that pulls from two tables, one of the tables is called accounts and the other is called agents.  They are joined by the AGENT to NAME.  The query produces the results just like I want them too, however, some of the customers have a default email address that we do not want to have in there.  For example here are my columns:
Customer Name       Customer Email           Agent Email     Name
_________________________________________________________
Bobby Joe              bobby@sales.com      default@blank.com    Jim
Sam Cole                Sam@abc.com            david@agent.com      David
Amy Jenn               amyj@xyz.com            defualt@blank.com    Ken

(3) records returned

If the agent email address matches default@blank.com then I would like it to say NULL instead I would still like it to return the 3 records just null in those columns.  

Let me know if you need anything else.  Thanks


SELECT     Telebill.dbo.Accounts.CustomerName, Telebill.dbo.Accounts.EmailAddress AS CustomerEmail, Telebill.dbo.Agents.EmailAddress AS AgentEmail, 
                      Telebill.dbo.Agents.Name
FROM         Telebill.dbo.Accounts INNER JOIN
                      Telebill.dbo.Agents ON Telebill.dbo.Accounts.Agent = Telebill.dbo.Agents.Name
WHERE     (Telebill.dbo.Accounts.EmailAddress IS NOT NULL)

Open in new window

Comment
Watch Question

SELECT     Telebill.dbo.Accounts.CustomerName, Telebill.dbo.Accounts.EmailAddress AS CustomerEmail, nullif(Telebill.dbo.Agents.EmailAddress,'defualt@blank.com') AS AgentEmail,
                      Telebill.dbo.Agents.Name
FROM         Telebill.dbo.Accounts INNER JOIN
                      Telebill.dbo.Agents ON Telebill.dbo.Accounts.Agent = Telebill.dbo.Agents.Name
WHERE     (Telebill.dbo.Accounts.EmailAddress IS NOT NULL)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Worked great!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.