Reputation: 1062
I'm trying to pull records from a table that are from the last two years. The field is stored as a datetime
data type in SQL Server 2008. The query I attempted is:
Where ChangeWho<>N'RMADMIN'
And ChangeWho<>N'dbo'
And ChangeWhen < dateadd(year,-2,getdate())
I do not want any records where the ChangeWho
is 'RMADMIN' or 'dbo' but I also only want records that have been changed within the last two years, from today's date.
Looking at my record set after the query has run, I see records from 2012 and before so it something apparently isn't correct with my ChangeWhen statement.
Any advice on how to correct it?
Thanks,
Upvotes: 0
Views: 521
Reputation: 1630
Try
Where ChangeWho<>N'RMADMIN'
And ChangeWho<>N'dbo'
And ChangeWhen > dateadd(year,-2,getdate())
Upvotes: 1