List rows after specific date

SqlSql ServerSql Server-2008Sql Server-2005

Sql Problem Overview


I have a column in my database called "dob" of type datetime. How do I select all the rows after a specific DoB in SQL Server 2005?

Sql Solutions


Solution 1 - Sql

Simply put:

SELECT * 
FROM TABLE_NAME
WHERE
dob > '1/21/2012'

Where 1/21/2012 is the date and you want all data, including that date.

SELECT * 
FROM TABLE_NAME
WHERE
dob BETWEEN '1/21/2012' AND '2/22/2012'

Use a between if you're selecting time between two dates

Solution 2 - Sql

Let's say you want to get all records from a table called Table_One with a datetime column called date_value that have happened in the past six months...

CREATE TABLE (
  date_value DATETIME
) 

SELCECT *
FROM Table_One
WHERE date_value > DATEADD(month, -6, getdate());

This gives a bit more dynamic of a solution.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBazView Question on Stackoverflow
Solution 1 - SqlcgatianView Answer on Stackoverflow
Solution 2 - SqlKen BrummageView Answer on Stackoverflow