且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL Server中的特定时间范围查询

更新时间:2023-11-05 17:21:58

我假设你想要所有这三个作为选择标准的一部分。你需要在你的位置提供几个陈述,但它们将与您的问题所在的链接相似。

I'm assuming you want all three of those as part of the selection criteria. You'll need a few statements in your where but they will be similar to the link your question contained.

SELECT *
  FROM MyTable
  WHERE [dateColumn] > '3/1/2009' AND [dateColumn] <= DATEADD(day,'3/31/2009',1) 
                 --make it inclusive for a datetime type
    AND DATEPART(hh,[dateColumn]) >= 6 AND DATEPART(hh,[dateColumn]) <= 22 
                 -- gets the hour of the day from the datetime
    AND DATEPART(dw,[dateColumn]) >= 3 AND DATEPART(dw,[dateColumn]) <= 5 
                 -- gets the day of the week from the datetime

希望有帮助。