• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 131
  • Last Modified:

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

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

0
binaryman101
Asked:
binaryman101
1 Solution
 
BrandonGalderisiCommented:
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)
0
 
binaryman101Author Commented:
Worked great!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now