使用本周/上周进行自动运行的报告

时间:2022-09-26 15:28:46

I have set the dates in the parameter as below, but I'm lost with the next bit... what I want is;

我已经在参数中设置了日期,如下所示,但我迷失了下一位......我想要的是;

If @TodayDayOfWeek < 5 (so it is Monday - Thursday) then run last week's dates (from @Startoflastweek - @endoflastweek) else use this weeks date range

如果@TodayDayOfWeek <5(所以它是星期一 - 星期四)然后运行上周的日期(来自@Startoflastweek - @endoflastweek),否则使用这周的日期范围

DECLARE @TodayDayOfWeek INT

DECLARE @EndOfThisWeek datetime

DECLARE @StartOfThisWeek datetime

DECLARE @EndOfPrevWeek DateTime

DECLARE @StartOfPrevWeek DateTime

SET @TodayDayOfWeek = datepart(dw, GetDate())

set @EndOfThisWeek =  DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 4)

set @StartOfThisWeek =  DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0)

SET @EndOfPrevWeek = DATEADD(dd, -@TodayDayOfWeek, GetDate())

SET @StartOfPrevWeek = DATEADD(dd, -(@TodayDayOfWeek+6), GetDate())

1 个解决方案

#1


0  

Assuming you are using SQL Server and this is SProc

假设您正在使用SQL Server,这是SProc

CASE WHEN @TodayDayOfWeek < 5 THEN
BEGIN
  -- YOUR LOGIC
END
ELSE
BEGIN 
  -- ELSE LOGIC
END

#1


0  

Assuming you are using SQL Server and this is SProc

假设您正在使用SQL Server,这是SProc

CASE WHEN @TodayDayOfWeek < 5 THEN
BEGIN
  -- YOUR LOGIC
END
ELSE
BEGIN 
  -- ELSE LOGIC
END