简体   繁体   English

数据驱动订阅上的SSRS参数数据参数失败

[英]SSRS Parameters Data Parameters Failing on Data Driven Subscription

I'm wondering if anyone is able to help. 我想知道是否有人能够提供帮助。

I have a suite of data driven subscriptions which uses the following SQL Code to calculate the parameter. 我有一套数据驱动的订阅,它使用以下SQL代码来计算参数。 This is the same SQL Server data source that the report uses too. 该报表也使用相同的SQL Server数据源。

 select cast(dateadd(day,case when datepart(dw,getdate()) in (5,6) then 4 else 2 end,getdate()) as date) [parameter]

The parameter in the report is of type date. 报告中的参数为日期类型。

This has been working for 15 months no problem but following a server upgrade last week, this is now stopped working. 这已经工作了15个月,没问题,但是在上周对服务器进行了升级之后,现在该服务器停止了工作。 When investigating, the error log said that the above was not giving a valid date. 在调查时,错误日志指出上述内容未提供有效日期。 If I manually enter a date in the report itself it works fine. 如果我在报告本身中手动输入日期,则效果很好。 If I specify a hard coded date in the subscription, and look at the report, the results now appear to be reversing the month and day parts of the date (for when that option gives a valid date). 如果我在订阅中指定了一个硬编码日期,然后查看该报告,则结果现在看起来像是反转了该日期的月和日部分(该选项提供有效日期的时间)。

As a temporary work around in the critical reports, I've managed to get this working by converting the result to varchar in the format 'yyyy-MM-dd' by changing the code to this: 作为关键报告中的一项临时工作,我设法通过将代码更改为yyyy-MM-dd格式将结果转换为varchar来使其工作:

select left(convert(varchar,dateadd(day,case when datepart(dw,getdate()) in (5,6) then 4 else 2 end,getdate()),126),10) [parameter]

Because of the volume of reports affected, it's not necessarily practical to do this for all the reports. 由于受影响的报告数量很大,因此对所有报告执行此操作不一定是切实可行的。

Any ideas for causes and potential fixes? 关于原因和潜在解决方案的任何想法?

I can see a reason to your code generates an error. 我可以看到您的代码生成错误的原因。 You can get wrong results because of the configuration of SET DATEFIRST on the server. 由于服务器上SET DATEFIRST的配置,您可能会得到错误的结果。

First, check your Datadirst with 首先,使用以下命令检查您的Datadirst

SELECT @@DATEFIRST  

And set it in your code like it 并像这样在您的代码中进行设置

DECLARE @Date date = '20170914' -- Thursday


SET DATEFIRST 1 ; 
SELECT datepart(dw,@Date) 
--Result 4 

SET DATEFIRST 2 ; 
SELECT datepart(dw,@Date) 
--Result 3

SET DATEFIRST 3 ; 
SELECT datepart(dw,@Date) 
--Result 2

SET DATEFIRST 4 ; 
SELECT datepart(dw,@Date) 
--Result 1

SET DATEFIRST 5 ; 
SELECT datepart(dw,@Date) 
--Result 7

SET DATEFIRST 6 ; 
SELECT datepart(dw,@Date) 
--Result 6

SET DATEFIRST 7 ; 
SELECT datepart(dw,@Date) 
--Result 5

SET DATEFIRST (Transact-SQL) 设置日期(Transact-SQL)

SET DATEFORMAT 设置日期格式

SET LANGUAGE (Transact-SQL) 设置语言(Transact-SQL)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM