비틀기를 SalesOrder를하고 주문일
감사를 참조 (올바른 출력으로 메시지를 표시합니다 SQL Server Management Studio에서 실행). PRINT
연산자를 당신의 SELECT
문을 필터링하고 제거 할 변수를 사용 @today 금요일보다 작 으면 ...
가
DECLARE @ReportDate DATETIME
DECLARE @StartOfWeek DATETIME
DECLARE @DayOfWeek INT
SET @ReportDate = '2014-05-15 00:00:00.000' --This will be your variable in report builder
SET @DayOfWeek = DATEPART(dw,@ReportDate)
/*
Take away the day of the week from the report date to
get the beginning of that week.
*/
--Adjust the +1 to mark the start of your week (ie. +2 makes Monday the start)
SET @StartOfWeek = DATEADD(dd, (-(@DayOfWeek) + 1), @Reportdate)
--Now do stuff based on the report date (set the beginning of the week)
IF @DayOfWeek BETWEEN 2 AND 5 --Friday is day 6 (Sunday is first day in SQL and the BETWEEN clause is inclusive)
BEGIN
PRINT 'Monday to Thursday' --This line can be removed
/* Now minus 7 to get the beginning of the previous week */
SET @StartOfWeek = DATEADD(dd, -7, @StartOfWeek)
END
---------------------------------------------------
/*
This entire box is optional (can be removed) but just for demonstration purposes to
show that the date stuff works
*/
IF @DayOfWeek = 6 --Friday is day 6
BEGIN
PRINT 'Friday'
END
IF @DayOfWeek IN (7,1) --Saturday day 7, Sunday day 1
BEGIN
PRINT 'Saturday or Sunday'
END
---------------------------------------------------
--This is where your SELECT statement goes (instead of PRINT operators below)
PRINT 'StartOfWeek = ' + CAST(@StartOfWeek AS NVARCHAR(255))
PRINT 'EndOfWeek = ' + CAST(DATEADD(dd,7,@StartOfWeek) AS NVARCHAR(255))
''- 당신이 @today은 * 금요일 또는 금요일보다 * 더 적은 경우'말을 의미 했 ... '? 또한 지금까지 무엇을 얻었습니까? 특히, 요일에 관계없이 범위를 선택하는 방법은 무엇입니까? –
'오늘'이 금요일 (예 : 주일 숫자로 5) 인 경우 '오늘'<5 인 경우 'StartOFPrevWeek'과 'EndOfPrevWeek'사이의 주문일 '오늘'> 5 인 경우 'StartOfThisWeek'과 ' 'EndOfThisWeek'. 나는 절의 구문과 매개 변수를 정의하는 방법에 어려움을 겪고있다. – JustAnAverageSQLuser
오늘 매개 변수를 int로 선언했습니다. – JustAnAverageSQLuser