Solved

need select statement

Posted on 2007-04-09
4
149 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 143

Expert Comment

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

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18876842
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
ID: 18876846
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
ID: 18876853
ok, I'll try the second one
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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