我有一个与 Windows 调度程序一起自动运行的程序。该程序运行一个使用昨天日期的存储过程,对我们的数据库运行查询以提取前一天的结果。此查询不包括全天的特定时间段,因为我们不关心这些结果。但是,我们星期天有不同的时间,并且想更改星期天的查询……如果是“星期天”,有没有办法以不同的方式查询?下面是我的存储过程:
CREATE PROCEDURE [dbo].[sp_Open_Close_Report_1] AS
declare @dtNow datetime , @dtToday datetime , @dtFrom datetime , @dtThru datetime , @dtExcludeFrom datetime , @dtExcludeThru datetime, @dtExcludeEOD datetime
set @dtNow = getdate()
set @dtToday = convert(datetime,convert(varchar,@dtNow,112),112)
set @dtFrom = dateadd(day,-1,@dtToday) -- start-of-day yesterday
set @dtThru = dateadd(ms,-3,@dtToday) -- end-of-day yesterday (e.g., 2012-06-17 23:59:59.997)
set @dtExcludeFrom = convert(datetime, convert(char(10),@dtFrom,120) + ' 05:30:00.000' , 120 )
set @dtExcludeThru = convert(datetime, convert(char(10),@dtFrom,120) + ' 06:15:00.000' , 120 )
set @dtExcludeEOD = convert(datetime, convert(char(10),@dtFrom,120) + ' 08:00:00.000' , 120 )
SELECT Store_Id , DM_Corp_Received_Date, Register_Transaction_Type
FROM Register_Till_Count_Tb
WHERE (Register_Transaction_Type = 'SOD' and store_ID = '12345'
AND DM_Corp_Received_date between @dtFrom
and @dtThru
AND DM_Corp_Received_date not between @dtExcludeFrom
and @dtExcludeThru) or (Register_Transaction_Type = 'EOD' and Store_ID='12345'
AND DM_Corp_Received_date Between @dtFrom and @dtThru)
周日@DTExclude
从 6:30 到@dtexcludeThru
7:15