Let’s say I have an employee table with columns:
Id, Name, Birthdate
I am trying to write SQL query to retrieve all employees who will be 21 in a month’s time, and another query to retrieve all employees who are currently 21.
I am using Microsoft SQL Server 2008.
I’m assuming you want to know employees at least 21 years old, not exactly 21 years old.
For one month from now:
WHERE BIRTHDATEField <= DATEADD(year, -21, DATEADD(month, 1 Getdate())Remove the last
Dateaddto use today.