问题描述
|
您好,我已经将电子表格转换为SSRS报表,该报表在每月20日运行,我需要通过自定义表达式或数据集将当前月份的20日作为默认值(开始日期)传递。如果20日是星期六,则默认为19日星期五。如果20日是星期日,则默认为星期五18日。我该怎么做?最好的方法是什么?
解决方法
这个怎么样:
DECLARE @daytwenty date;
SET @daytwenty = DATEADD(mm,DATEDIFF(mm,getdate()),19) --Get Twentieth Day of current month
SELECT
CASE DATEPART(DW,@daytwenty)
WHEN 1 THEN DATEADD(dd,-2,@daytwenty) --When the twentieth day is a Sunday,take two days off
WHEN 7 THEN DATEADD(dd,-1,@daytwenty) --When the twentieth day is a Saturday,take one day off
ELSE @daytwenty --Else the twentieth day is a weekday already
END
, 您应该将Datetime用于2008版本。通过写
DECLARE @LatestDate date;
在早期版本的Sql Server中给出了编译错误。
Column,parameter,or variable #1: Cannot find data type date.
所以下面是代码Sql Server 2008
DECLARE @LatestDate datetime;
SET @LatestDate = DATEADD(mm,@LatestDate)
WHEN 1 THEN DATEADD(dd,@LatestDate) --When the twentieth day is a Sunday,@LatestDate) --When the twentieth day is a Saturday,take one day off
ELSE @LatestDate --Else the twentieth day is a weekday already
END
, 我希望这就是你想要的
select case datename(dw,getdate())
when \'Monday\' then \'Friday\'
when \'Tuesday\' then \'Monday\'
when \'Wednesday\' then \'Tuesday\'
when \'Thursday\' then \'Wednesday\'
when \'Friday\' then \'Thursday\'
when \'Saturday\' then \'Friday\'
when \'Sunday\' then \'Friday\'
end