在 SQL Server 中添加 +- 1 年 [英] add +- 1 year in SQL Server
本文介绍了在 SQL Server 中添加 +- 1 年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试选择年份模型在当前年份 +1 到 -1 之间的产品.而且我只想要年份(前 2011 年)而不是完整的日期和时间.
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...
推荐答案
您将 1 添加到 getdate() 所以您添加了 1 天
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)
这篇关于在 SQL Server 中添加 +- 1 年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文