Solved

need select statement

Posted on 2007-04-09
4
144 Views
Last Modified: 2010-03-19
how do I modify this sql select statement to include some if/then logic:
SELECT DISTINCT EMAIL FROM  tblBLAH WHERE division_name=@division_name and mgr_email=@mgr_email

I want to add to this that if @division_name is 'unknown' then we need the filter to be where division_name is null...
0
Comment
Question by:acdagirl
  • 2
  • 2
4 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
SELECT DISTINCT EMAIL
FROM  tblBLAH
WHERE ( division_name=@division_name OR @division_name =  'unknown'  )
AND mgr_email=@mgr_email
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
sorry, a small correction:

SELECT DISTINCT EMAIL
FROM  tblBLAH
WHERE (   ( division_name=@division_name AND @division_name <> 'unknown'  )
       OR (division_name IS NULL AND @division_name = 'unknown'  )
      )
AND mgr_email=@mgr_email
0
 

Author Comment

by:acdagirl
Comment Utility
no, that's not what I want. it's *if* the parameter @division_name comes in as 'unknown' then select division_name is null
0
 

Author Comment

by:acdagirl
Comment Utility
ok, I'll try the second one
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now