0

我在我的 asp.net 应用程序中使用 gridview,我想将数据集限制为在当前月份和年份提交的请求

我是应用程序开发的新手,并以以下方式思考

从 getdate() 函数中获取月份和年份部分,然后在 where 条件下将其与我们表中 receiveddate 列的月份和年份进行比较

我的选择语句如下

从 customerrequests 中选择 requestno,receiveddate,businessneed where receiveddate = getdate()

在上面的 sql 语句中我如何实现

4

2 回答 2

1

There are two ways you could do this:

  • In SQL by passing two parameters for month and year. This is what your questions sounds like and can be done by just doing this:

    select requestno,receiveddate,businessneed from customerrequests where YEAR(receiveddate) = YEAR(getdate()) AND MONTH(receiveddate) = MONTH(getdate())

  • The other way would be to construct a date object on the client side and pass that in to your query and then just use regular date comparison techniques.

Hope that helps.

于 2012-10-30T19:35:15.990 回答
0

您可以执行以下操作:

DECLARE @FirstDate DATETIME    
SELECT @FirstDate = DATEADD(month, DateDiff(Month, 0, GETDATE()), 0)

SELECT 
      requestno,receiveddate,businessneed 
FROM 
      customerrequests 
WHERE 
      receiveddate >= @FirstDate

希望这可以帮助!!

于 2012-10-30T19:39:54.463 回答