Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Analysis Server and Reporting Services (2005)
 Case Statement in a Where Clause?

Author  Topic 

nokiauk
Starting Member

9 Posts

Posted - 2012-06-18 : 04:42:02
Hi

I've got a SQL report that has various columns the 2 that are important here are :

Person.Gender
Age

I need a statement (case or if) in my where clause that can accomplish the following:

I only want to return rows when if the Person.Gender is Male and under is under 65 and if Person.Gender is Female and age is under 61.

Not sure how to utilize the 2 columns?

Thanks

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2012-06-18 : 04:49:59
You can try some thing like this

Select * from table_name where (gender='male' and age<65) or (gender='female' and age<61)

Senthil Kumar C
------------------------------------------------------
MCITP - Database Administration SQL SERVER 2008
MCTS - Database Development SQL SERVER 2008
Go to Top of Page
   

- Advertisement -