I had the following query running in a package setup that gets the records for the previous day in a table that includes the following columns:
url, author, dateadded
Now the dateadded is in datetime format as follows 2012-08-23 23:58:42.000 and the query as follows:
SELECT [authorUrl],[author],
[dateadded]
FROM [Feeds].[dbo].[DataFeed]
where dateadded > dateadd(day,datediff(day, 0, getdate()-1), 0)
and dateadded < dateadd(day,datediff(day, 0, getDate()), 0)
Now the count of this query does not match the count of the following query which I would have to alter each day to insert the dates:
SELECT [authorUrl]
,[author]
,[dateadded]
FROM [Feeds].[dbo].[DataFeed]
where dateadded > '2012-08-22 23:59:59' and dateadded < '2012-08-23 23:59:59'
Is there something I am missing here?
Perhaps I should emphasize that the dateadded column is one that I edit(inserted from the app) and not an auto inserted date by sql itself.
Stop using weird edges and needlessly complex expressions for date ranges. Since you are on 2008, the proper way to get yesterday is:
Or you can take advantage of the fact that SQL Server 2008 makes this query sargable (which doesn’t work in almost every other case you could imagine):