返回首页

您好,

我需要从两个表显示匹配的记录。参数是用户每月为一个单一的数字即1月和今年将进入到12.now是没有问题的,但我需要如两个月内记录显示,如果用户进入1/2011,然后我需要显示1/2011和12/2010,即从本月匹配记录匹配的记录由用户输入,1个月以前从该。一个月是不是我想一个好的解决方案。没有任何人有更好的解决方案。预先感谢

回答

评论会员:chitra81 时间:2012/02/05
I found the answer i can write query this way

 

select ------where(months=@months and years=@years) or (months=@months-1 and years=@years-1) where @months and @years are the parameters user is entering, and it is working in any case



thanks for ur consideration
评论会员:米卡Wendelius 时间:2012/02/05
如果这是SQL Server,您可以使用例如]

[加]
你的意思是这样的:
{C}例如在一天的部分将是一个常数,始终为1。与这些界限,你可以搜索记录,例如,如:
SELECT ...

FROM ...

WHERE SomeDateField >= dateadd(m, -1, convert(date, '1/1/2011', 103))

AND   SomeDateField <  dateadd(m, +1, convert(date, '1/1/2011', 103))