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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Age between 19 and 24

Status
Not open for further replies.

TomR100

Programmer
Aug 22, 2001
195
US
Hello again everybody,
I have a query that has a student field. The filed can only be set to yes if the age is between 19 and 24.

Can I write a CASE for this or do a DATEDIFF?

Thank you once again.
TOMR100
 
SELECT [list of fields...],
CASE WHEN (Age < 24 AND Age > 19) THEN 'Yes'
ELSE 'No'
END AS 'Student'
FROM .....
 
You can use the CASE and DATEDIFF functions in T-SQL.

Select
col1, col2, col3,
col4 =
Case
When datediff(d,birthdate,getdate())/365.25
Between 19 And 24 Then 'yes'
Else 'no'
End
From table_name Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains &quot;Suggestions for Getting Quick and Appropriate Answers&quot; to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top