我正在尝试学习如何使用Reporting Services,并且一直在与我导出了想要的项目一起工作。我已经对其进行了增强,使其使用了可以过滤的变量,并且正在尝试将变量添加到数据集查询中。
这是我遇到麻烦的地方。下面是我的查询,它工作正常。
DECLARE @reqDateTime VARCHAR(16), @TSQL nvarchar(4000)
SET @reqDateTime = '2014-01-14'
SET @TSQL = 'select convert(datetime, ''<<date>>'') Timestamp, <<other Columns>>
from openquery
(<<server>>, ''SELECT ...etc...'')
order by <<other Columns>>'
SET @TSQL = REPLACE(@TSQL, '<<date>>', @reqDateTime)
exec (@TSQL)
但是,当我将其更改为此并在属性中设置“参数”时,出现错误。
代码:
DECLARE @reqDateTime VARCHAR(16), @TSQL nvarchar(4000)
SET @reqDateTime = @filterByDateTime
SET @TSQL = 'select convert(datetime, ''<<date>>'') Timestamp, <<other Columns>>
from openquery
(<<server>>, ''SELECT ...etc...'')
order by <<other Columns>>'
SET @TSQL = REPLACE(@TSQL, '<<date>>', @reqDateTime)
exec (@TSQL)
参数名称:@filterByDateTime
参数值:[@AsAt]
非常重要的是,我也将时间传递给DateTime,它基于此数据集:
select dateadd(mi, datediff(mi, 0, getdate()) - (datediff(mi, 0, getdate()) % 5), 0) [DefaultDateTime]
这将返回类似(最后5分钟的增量)的内容:2014-01-14 17:25:00.000
当我设计查询时,弹出窗口要求@filterByDateTime的默认值时,我将其设置为'2014-01-14 05:25:00 PM',查询运行并获取行名。
在生成器中运行报告时,虽然出现以下消息:
For more information about this error navigate to the report server on the local server machine, or enable remote errors
----------------------------
Query execution failed for dataset 'MainDataSet'. (rsErrorExecutingCommand)
----------------------------
An error has occurred during report processing. (rsProcessingAborted)
我在这里做错了什么?
我已经解决了这个问题。这是由于通过openquery将查询传递到的Oracle服务器想要以其格式指定的日期。这是通过对参数的表达式进行以下更改来解决的:
=year(Parameters!AsAt.Value) & "-" & Right("00" & Month(Parameters!AsAt.Value), 2) & "-" & Right("00" & Day(Parameters!AsAt.Value), 2) & " " & Right("00" & Hour(Parameters!AsAt.Value), 2) & ":" & Right("00" & Minute(Parameters!AsAt.Value), 2)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句