SQLTeam.com | Weblogs | Forums

Only show rows from yesterday

tsql
sql2014

#1

SQL Version: MS SQL 2014
Column Data Type: Date

Hi, i'm just hoping I can get some suggestions.
All I'm trying to do is select rows from yesterday. (Assuming today is 2015-11-22)

Sample Data:

date
2015-11-18
2015-11-19
2015-11-20
2015-11-21 <--- Today is 2015-11-22 so I only want to see these rows
2015-11-21 <--- Today is 2015-11-22 so I only want to see these rows
2015-11-21 <--- Today is 2015-11-22 so I only want to see these rows
2015-11-22

My poorly constructed SQL code.
SELECT date From myTable
where date = convert(smalldatetime, GETDATE(), 110) - 1

Output:
NOTHING. Just a column name with no rows and no errors.


#2

WHERE date = convert(date, getdate() - 1)


#3

Thank you Khtan!