简体   繁体   English

Report Builder 3.0-如何编写读取所有parm名称和值的SQL?

[英]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: 棘手的部分:

  1. There are many parameters, so manually coding for each parameter would take too long. 参数很多,因此手动编码每个参数会花费很长时间。 Need a way to loop through. 需要一种循环的方式。

  2. Some parameters might be left blank and some might be NULL 有些参数可能留为空白,有些则可能为NULL

  3. 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.

相关问题 如何修改MySQL查询以在Report Builder 3.0中工作? - How can I modify a MySQL query to work in Report Builder 3.0? 如何使用报表生成器3.0将SQL查询中的列名作为参数传递 - How to pass column names in a SQL query as parameters using report builder 3.0 基于单元格值的表总计列-SQL Report Builder 3.0 - Table Total Column based on cell values - SQL Report Builder 3.0 Report Builder 3.0基础SQL - Report Builder 3.0 underlying SQL Report Builder 3.0 - 如何使用大型数据集运行此报告? - Report Builder 3.0 - How can I run this report with a large data set? Report Builder 3.0:如何为该文本框指定数据集? - Report Builder 3.0: How do I specify the dataset for this textbox? 如何在特定字段中显示多个参数值的所有值? SQL Server报表生成器 - How to display all values in a particular field for multiple parameter values? SQL Server Report Builder SQL代码可在SSMS中工作,但不能在Report Builder 3.0中工作 - SQL Code working in SSMS but not in Report Builder 3.0 在使用SQL SERVER REPORT BUILDER 2014滚动SSRS报告时,如何保持标题(列名)可见? - How do I keep the header (column names) visible while scrolling in an SSRS report USING SQL SERVER REPORT BUILDER 2014? Report Builder 3.0如何在不同的列上进行过滤 - Report Builder 3.0 How to filter on different columns
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM