Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CASE Condition for WHERE Clause

Status
Not open for further replies.

chouna

Programmer
Mar 28, 2003
75
DE
Can someone give me an example of a SQL statement which embeds the CASE condition on WHERE clause? E.g.

Select the fields Employee, Gender, Division from the table "Employees" where (if the Gender = "Male" Division = "Sales", if Gender = "Female" Division = "Accounts").

So for Male gender, only male employees in Sales division should show. For Female gender, only female employees in Accounting will show.

I know there could be other ways but I would like it to see it in the WHERE clause which is dictated by other conditions.
 
Code:
Select Employee, Gender, Division 
from Employees
where (Gender = 'Male' and  Division = 'Sales')
or (Gender = 'Female' and Division = 'Accounts')
 
Thank you swampBoogie. This will satisfy the example but I was thinking more along the line of a multiple condition handled by the CASE statement. What if there are more conditions to be met, can we enCASE them within WHERE clause? If so, how is it done in this example or any other example will do.






 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top