Reporting Services - Multi-value parameter query returning no results

别等时光非礼了梦想. 提交于 2020-01-11 10:24:07

问题


Using SSRS (SQL Server 2005) I've set up two reports. For ease of explanation, let's call them MAIN_REPORT and SUB_REPORT.

MAIN_REPORT runs a query that returns a set of Areas, with multiple TagNames per area:

AREA    Tagname
----------
A1        T1
A1        T2
A2        T3
A3        T4

If you select one of the Area cells, it opens SUB_REPORT and passes a parameter to @ParentTagNames using Join(Parameters!ResultsOfSearch.Value,","). ResultsOfSearch is equal to the Tagname column above (haven't yet figured out how to limit the Tagnames to only the ones in the selected area, but I'll worry about that later).

SUB_REPORT takes the passed parameter and queries a massive database for the tagname, and returns a min, max, and average of available values:

SELECT
h.TagName as TagName,
Minimum = convert(decimal(38, 2), Min(h.Value)), 
Maximum = convert(decimal(38, 2), Max(h.Value)), 
Average = convert(decimal(38, 2), Avg(h.Value)) 
FROM INSQL.Runtime.dbo.History h 
WHERE h.TagName in (@ParentTagNames)
AND h.wwVersion = 'LATEST'
AND h.wwRetrievalMode = 'Cyclic'
AND h.wwResolution = '60000'
AND h.Value > '-1.0'
AND h.DateTime >= '2009-09-01 12:00:00'
AND h.DateTime <= '2009-09-02 16:00:00'
GROUP BY h.TagName

However, if @ParentTagNames is equal to more than one value, it returns no data. If it's equal to a single tag, it returns data. I figured it must have had something to do with the formatting of the data within @ParentTagNames as it's passed from MAIN_REPORT, but it doesn't seem to matter.

I've tried the following formats:

T1,T2,T3,T4,T5,T6
'T1','T2','T3','T4','T5','T6'

I made sure the multi-value is checked for the parameter @ParentTagNames. Google has successfully failed me.

Anyone?

EDIT: Profiler magic!

exec sp_executesql N'SELECT
    h.TagName as TagName,
    Minimum = convert(decimal(38, 2), Min(h.Value)), 
    Maximum = convert(decimal(38, 2), Max(h.Value)), 
    Average = convert(decimal(38, 2), Avg(h.Value)) 
FROM INSQL.Runtime.dbo.History h 
WHERE h.TagName in (@ParentTagNames)
AND h.wwVersion = ''LATEST''
AND h.wwRetrievalMode = ''Cyclic''
--AND h.wwResolution = @Resolution
AND h.wwResolution = ''60000''
AND h.Value > ''-1.0''
--AND h.DateTime >= @StartTime
--AND h.DateTime <= @EndTime

AND h.DateTime >= ''2009-09-01 12:00:00''
AND h.DateTime <= ''2009-09-02 16:00:00''

GROUP BY h.TagName',N'@ParentTagNames nvarchar(46)',@ParentTagNames=N'M12_CPM_Filling_250.Value,M8_Filling_391.Value'

回答1:


I think you may need a SPLIT call on the MAIN_REPORT to force SSRS to take the incoming parameter and put it into an array.

Reference: http://www.stuffthatjustworks.com/HowToPassMultivalueReportParametersToSubreportsInReportBuilder.aspx



来源:https://stackoverflow.com/questions/11108060/reporting-services-multi-value-parameter-query-returning-no-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!