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
 General SQL Server Forums
 New to SQL Server Programming
 Select With Conditions

Author  Topic 

mike1973
Starting Member

46 Posts

Posted - 2011-01-13 : 03:57:48
Hello

Please can anyone help in writing a query with some if conditions?

the query is supposed to select the Top 5 children from a table called children
where

IF Child.sex=Male
(child.Studying=True AND (Today-Child.BirthDate > 21)) OR Child.Handicap=True OR (Today-Child.Birthdate) > 18
then
if Child.Works=False OR Child.Married=False
else

Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-01-13 : 04:28:13
[code]
WHERE
(
(
child.sex = 'Male' AND (child.Studying='True' AND DATEDIFF(YEAR,Child.BirthDate,getdate()) > 21)
OR Child.Handicap='True'
OR DATEDIFF(YEAR,Child.BirthDate,getdate()) > 18
)
AND Child.Works='False' OR Child.Married='False'
)
OR
(
...
)
[/code]


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -