[英]Report Builder 3.0 - How can I write SQL that reads all parm names and values?
Example: 例:
Parameter: parm
参数: parm
Label: ParmLabel
标签: ParmLabel
Value: value
价值: value
The user is going to select the value of the parameter they want, then run the report. 用户将选择所需的参数值,然后运行报告。 When the report loads, I want to display on the report a URL string containing all of the parameters & the values they selected. 加载报告时,我想在报告上显示一个URL字符串,其中包含所有参数及其选择的值。 How can I do this? 我怎样才能做到这一点?
The tricky parts: 棘手的部分:
There are many parameters, so manually coding for each parameter would take too long. 参数很多,因此手动编码每个参数会花费很长时间。 Need a way to loop through. 需要一种循环的方式。
Some parameters might be left blank and some might be NULL 有些参数可能留为空白,有些则可能为NULL
All the parameters could have different data types, so the solution would need to be independent of data type. 所有参数可能具有不同的数据类型,因此解决方案将需要独立于数据类型。
What I've tried: 我试过的
This worked, but it is not realistic to do this for every report and every parameter within that report. 这是可行的,但为每个报告和该报告中的每个参数执行此操作并不现实。 This method required me to go into the DataSet Properties and pass in the values for multi-valued parameters as a comma separated string of values, which was annoying. 此方法要求我进入“数据集属性”,并将多值参数的值作为逗号分隔的值字符串传递,这很烦人。 I'd like to avoid this as well if possible. 如果可能的话,我也想避免这种情况。
select
(@URL
+
case
when len(@parm) <> 0 --This works. The query skips the parm if no values (or only blank values) are passed.
then '&parm=' + replace(@parm, ',', '&parm=')
else '' --Parm has no values
end
) as URLString
I can think of one hack for you here. 我可以在这里为您想到一个技巧。 This is untested and probably will need polish. 这未经测试,可能需要抛光。
1) First build a dataset to return a dynamic table query and inside the dataset add a query similar to below. 1)首先构建一个数据集以返回动态表查询,然后在数据集内添加类似于以下内容的查询。 This should generate a table with X number of records. 这将生成一个具有X条记录的表。 The idea is to set X to the number of parameters the user had made use of on your report. 想法是将X设置为用户在报表上使用的参数数量。
DECLARE @RowCount INT=4
;WITH T AS(
SELECT N=1
UNION ALL
SELECT N + 1 FROM T WHERE N + 1 <= @RowCount
)
SELECT RowNumber=N FROM T
OPTION (MAXRECURSION 255);
2) Add a tablix or table to your report and set the data source to the data source created above. 2)将Tablix或表格添加到报表中,并将数据源设置为上面创建的数据源。
3) Add your labels for the parameter details inside the table created in step 2. 3)在步骤2中创建的表中添加参数详细信息的标签。
4) Add a custom code procedure to return details for each parameter. 4)添加一个自定义代码过程以返回每个参数的详细信息。
Public Function GetParameter(ByVal parameters as Parameters, ByVal index as Integer) as Parameter
Return parameters(index)
End Function
5) Add a custom code procedure to return the parameter count. 5)添加一个自定义代码过程以返回参数计数。
Public Function GetParameterCount(ByVal parameters as Parameters) as Integer
Return parameters.Count()
End Function
6) Fill the row count parameter with the count above 6)用上面的计数填充行计数参数
7) Fill the labels using their expressions 7)使用其表达式填充标签
=Code.GetParameter(Parameters,Fields!RowNumber).Value
=Code.GetParameter(Parameters,Fields!RowNumber).Name
=Code.GetParameter(Parameters,Fields!RowNumber).DisplayLabel
...
MSDN Documentation on accessing Report Parameters in Custom Code 有关在自定义代码中访问报告参数的MSDN文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.