Reputation: 425
I try to select the Products that has a yearmodel between +1 and -1 the current year. And I only want the Year (ex 2011) not the full date and time.
SELECT ProductName FROM tblProduct WHERE Year BETWEEN
year(getdate()+1) AND year(getdate()-1)
Does not work, but something similar maybe...
Upvotes: 18
Views: 65951
Reputation: 211
SELECT dateadd(year, -1, getdate())
Would have done:
SELECT productname
FROM tblproduct
WHERE [year] between (select dateadd(year, -1, getdate()) AND (select dateadd(year, +1, getdate())
Upvotes: 21
Reputation: 8008
You are adding the 1 to getdate() so you are adding 1 day
SELECT ProductName FROM tblProduct WHERE Year BETWEEN
(year(getdate()) -1) AND (year(getdate()) + 1)
Upvotes: 21