If you ever wanted a simple way to get the last several days history using a DateTime column you can simply create a couple of DateTime Variables, and supply them with todays date, or todays date minus several days. This way you can include the last 7 days in your query logic.
Here’s a quick example:
use MyDatabase set nocount on declare @today datetime = ( select getdate() ) declare @last_7_days datetime = ( select getdate() - 7 ) -- today minus 7 days select , 'CreateDate' = convert(char, CreateDate, 9) , 'CreateDate' = CreateDate from MyDatabase.MyTable where CreateDate > @last_7_days -- include it with a greater than sign in the where clause and you will get the last several days. order by timestamp asc