ssrs 级联参数

This article covers the usage and detailed features of the multi-value parameter in SSRS.

本文介绍SSRS中多值参数的用法和详细功能。

介绍 (Introduction)

SQL Server Reporting Service also known as SSRS is a reporting tool of Microsoft that helps to develop various reports types. In addition, a few months ago Microsoft announced the first release candidate of SQL Server 2019 Reporting Service. This means that SSRS is still a powerful tool in the market and at the same time it plays a key role for companies who need to build custom reports and mobile reports.

SQL Server报告服务(也称为SSRS)是Microsoft的报告工具,可帮助开发各种报告类型。 此外,几个月前,微软宣布了SQL Server 2019 Reporting Service的第一个候选版本 。 这意味着SSRS仍然是市场上强大的工具,同时对于需要构建自定义报告和移动报告的公司而言,它起着关键作用。

Report Builder is a lightweight tool that helps to develop reports for SQL Server Reporting Service. In this article examples, we will use Report Builder. You can refer to SSRS Report Builder introduction and tutorial article for more detail about the SSRS report builder.

报表生成器是一种轻量级的工具,有助于为SQL Server报表服务开发报表。 在本文的示例中,我们将使用报表生成器。 您可以参考SSRS报告构建器简介和教程文章,以获取有关SSRS报告构建器的更多详细信息。

Now, let’s focus on the main topic that parametrized reports gain us more flexibility and provide an enhanced user experience. Starting from this point of view, we will learn the multi-value parameters in order to develop more advanced reports.

现在,让我们集中讨论参数化报表为我们提供更大的灵活性并提供增强的用户体验的主要主题。 从这个角度出发,我们将学习多值参数,以便开发更高级的报告。

什么是多值参数? (What is the multi-value parameter? )

The multi-value parameter allows us to pass either one or more than the input value to the report. Also, it offers a “Select All” option that helps to select all parameter values. Now, we will create an example of the multi-value parameter in SSRS.

多值参数使我们可以将一个或多个输入值传递给报表。 此外,它提供了“全选”选项,可帮助选择所有参数值。 现在,我们将在SSRS中创建一个多值参数示例。

示例场景 (Example scenario)

The Adventureworks human resources department required a report about the employees who are working in the company. They want to see the identity number, birth date, marital status and gender of the employee in the report. Furthermore, they want to filter the employees according to their job titles. They sent a draft about the report which is illustrated below:

Adventureworks人力资源部要求提供有关在公司工作的员工的报告。 他们想在报告中查看员工的身份证号码,出生日期,婚姻状况和性别。 此外,他们希望根据员工的职位筛选员工。 他们发送了有关该报告的草稿,如下所示:

在报表生成器中创建数据源 (Create a Datasource in Report Builder)

As the first step, we will launch the Report Builder and then select the Blank Report option in the Getting Started window:

第一步,我们将启动“报告生成器”,然后在“入门”窗口中选择“ 空白报告”选项:

This option helps us to open an empty report designer screen quickly. A little disadvantage of this option is to set some options manually. For this reason, we will create a data source and dataset of the report manually.

此选项有助于我们快速打开空白的报表设计器屏幕。 此选项的一个小缺点是手动设置一些选项。 因此,我们将手动创建报告的数据源和数据集。

In SSRS, data sources stored detailed information and credentials about the connections. In the Repor Builder main window, data sources are placed on the right side of the screen, we will right-click and select Add Data Source option to add a new data source:

在SSRS中,数据源存储有关连接的详细信息和凭据。 在Repor Builder主窗口中,数据源位于屏幕的右侧,我们将右键单击并选择Add Data Source选项以添加新的数据源:

On the Data Source Properties window, we can find various connection types that can be used in the reports. We will use the Microsoft SQL Server connection type for our report and select Use a connection embedded in my report and give HRReportDataSourcename:

在“数据源属性”窗口中,我们可以找到可以在报告中使用的各种连接类型。 我们将为报告使用Microsoft SQL Server连接类型,然后选择“ 使用嵌入到我的报告中的连接”,并提供HRReportDataSourcename

We can either fill the Connection string text box manually or we can use the Build option in order to generate a connection string. We will click the Build button and set up the credentials of the connection string:

我们可以手动填充“ 连接字符串”文本框,也可以使用“ 生成”选项来生成连接字符串。 我们将单击Build按钮并设置连接字符串的凭据:

After setting up the connection string, we will click the Test Connection button to be sure that we have set the proper settings:

设置连接字符串后,我们将单击“ 测试连接”按钮以确保我们设置了正确的设置:

If we see the “Connection created successful” message, we can figure out that all options are properly configured for the data source.

如果看到“连接创建成功”消息,则可以确定为数据源正确配置了所有选项。

在报表生成器中创建数据集 (Create a dataset in Report Builder)

Dataset is used to represent the result set of the query in the Report Builder reports. It stores detailed pieces of information about the resultset such as query string, column names, data types of the columns and etc. However, the dataset never stores the actual resultset of the query.

数据集用于表示报表构建器报表中查询的结果集。 它存储有关结果集的详细信息,例如查询字符串,列名,列的数据类型等。但是,数据集从不存储查询的实际结果集。

For our example, we will right-click on the Datasets folder in the Report Data tab and click the Add Dataset option:

对于我们的示例,我们将右键单击“报告数据”选项卡中的“数据集”文件夹,然后单击“ 添加数据集”选项:

In the Dataset Properties window, we will choose the Use a dataset embedded in my report option so that the dataset which is created in the previous step will appear in the Data source combo box. We will select the HRReportDataSource data source for this dataset and will give a name which is HRReportReportDataset:

在“数据集属性”窗口中,我们将选择“ 使用嵌入到我的报表中的数据集”选项,以便在上一步中创建的数据集将出现在“数据源”组合框中。 我们将为此数据集选择HRReportDataSource数据源,并将命名为HRReportReportDataset

After these settings, we will use the following script in order to get data from SQL Server:

完成这些设置后,我们将使用以下脚本从SQL Server获取数据:

SELECT[NationalIDNumber],[BirthDate],[MaritalStatus],[Gender]FROM [HumanResources].[Employee]WHERE JobTitle IN (@JobTitleParam)

As you can see in the above, the script contains a variable that is defined as @JobTitleParam. This parameter can be used to supply input for the report so that we can filter and control the query resultsets. Particularly for this report, it filtered the query according to the JobTitle. As the last step, we will click Refresh Fields and click OK:

如上所示,该脚本包含一个定义为@JobTitleParam的变量。 此参数可用于为报告提供输入,以便我们可以过滤和控制查询结果集。 特别是对于此报告,它根据JobTitle过滤了查询。 作为最后一步,我们将单击“ 刷新字段” ,然后单击“ 确定”

After we complete this step, @JobTitleParam will appear under the Parameters folder and the report columns also appear under the Dataset folder:

完成此步骤后, @ JobTitleParam将出现在Parameters文件夹下,并且报表列也出现在Dataset文件夹下:

报表制作工具中的多值参数 (The multi-value parameter in Report Builder)

The @JobTitleParam parameter has been created automatically, however, we need to associate it to the JobTitle column values of the HumanResources.Employee table. To do this, we will create a new dataset and associate the returning values to @JobTitleParam so that we can filter the HRReportReportDataset query according to these values. We will add a new dataset whose name is HRReportParameterDataset and use the following query:

@JobTitleParam参数是自动创建的,但是,我们需要将其与HumanResources.Employee表的JobTitle列值相关联。 为此,我们将创建一个新的数据集并将返回值关联到@JobTitleParam,以便我们可以根据这些值过滤HRReportReportDataset查询。 我们将添加一个名为HRReportParameterDataset的新数据集,并使用以下查询:

select distinct JobTitle FROM [HumanResources].[Employee]

We will right-click the @JobTitleParam parameter and choose Parameter Properties in the context menu:

我们将右键单击@JobTitleParam参数,然后在上下文菜单中选择“ 参数属性 ”:

We will click the Allow multiple values option in the General tab so that we can determine the parameter as a multi-value parameter and then change the Prompt field. This changing will affects the parameter’s showing name in the report. After these settings, we will click to the Available Values tab:

我们将在“ 常规”选项卡中单击“ 允许多个值”选项,以便可以将参数确定为多值参数,然后更改“提示”字段。 此更改将影响参数在报告中的显示名称。 完成这些设置后,我们将单击“ 可用值”选项卡:

Through this tab, we will associate a relation between dataset query result values and parameters. At first, we will select the Get values from a query so that we can create a connection between dataset, and parameter. In the second step, we can determine the value field and label field for the parameter.

通过此选项卡,我们将关联数据集查询结果值和参数之间的关系。 首先,我们将选择从查询中获取值,以便我们可以在数据集和参数之间创建连接。 在第二步中,我们可以确定参数的值字段和标签字段。

  • Value field specifies the values which are passed to the queries 值字段指定传递给查询的值
  • Label field specifies the values which are displayed in the report 标签字段指定报告中显示的值

For our example, we will set these options as shown in the below image:

对于我们的示例,我们将如下图所示设置这些选项:

在报表生成器中设计报表 (Designing report in Report Builder)

In this part, we will design a very basic report that described in our scenario:

在这一部分中,我们将设计一个非常基本的报告,该报告在我们的方案中进行了描述:

  • Insert in the Report Builder menu 插入
  • Table button and select the 表格按钮,然后在菜单上选择Insert Table option on the menu 插入表格选项。
  • HRReportReportDataset columns to the table HRReportReportDataset列拖放到表中
  • Change the footer of the report as Employee detail report
    将报表的页脚更改为“员工详细信息”报告

Finally, we will click the Run button to see the report. If we click (Select All) options, it will select all parameter values or we can make individual parameter value selections. View Report option is used to execute the report:

最后,我们将单击“ 运行”按钮以查看报告。 如果单击(全选)选项,它将选择所有参数值,或者我们可以选择单个参数值。 查看报告选项用于执行报告:

The IN operator is used to specified multiple values in the query. The executed query can find out in the profiler and it will be like as below:

IN运算符用于在查询中指定多个值。 执行的查询可以在事件探查器中找到,如下所示:

设置多值参数的默认值 (Setting default values for multi-value parameters)

In some cases, we need to populate the parameter values with the defaults. For example, if we want to access the Accounts Manager value to be the default for the @JobTitleParam, we can determine in the Default Values tab. At first, we choose the Specify values option and then write it into the value field:

在某些情况下,我们需要使用默认值填充参数值。 例如,如果我们要访问Accounts Manager值作为@ JobTitleParam默认值 ,则可以在“ 默认值”选项卡中确定。 首先,我们选择“指定值”选项,然后将其写入值字段:

Setting default values of the multi-value parameter

After these settings, the outcome of the report will be as below:

完成这些设置后,报告的结果将如下所示:

If we want to set Select All option as a default parameter we need to follow the steps below:

如果我们要将全选选项设置为默认参数,则需要执行以下步骤:

  • Get values from a query under the Default Values tab “从查询中获取值”
  • Set HRReportParameterDataset into the Dataset Combobox
  • HRReportParameterDataset设置为“数据集”组合
  • JobTitle field into the Value field JobTitle字段设置为Value字段

If we run the report, we can see that all values are selected in the first execution of the report.

如果运行报告,我们可以看到在第一次执行报告时选择了所有值。

显示多值参数的选定值 (Display selected values of the multi-value parameter )

Expressions are used to generate custom functions in the SSRS reports with the help of the built-in functions and custom codes. In order to display the selections of the multi-valued parameter, we will use expressions. Join function can be used to concatenate the selected values of the multi-value parameter. If we follow the below steps, we can display the selection of the multi-value parameter:

借助内置函数和自定义代码,可以使用表达式在SSRS报告中生成自定义函数。 为了显示多值参数的选择,我们将使用表达式。 连接功能可用于连接多值参数的选定值。 如果执行以下步骤,则可以显示多值参数的选择:

  • Add a textbox to the report
    在报告中添加文本框
  • Right-click on the textbox and select the Expression menu item

    右键单击文本框,然后选择“ 表达式”菜单项

  • Fill the value field with the below expression:

    用以下表达式填充值字段:

    "Parameter Values: " & JOIN(Parameters!JobTitleParam.Value, ", ")
    
    Displaying the multi-value parameter selections with help of the expression

If we select more than one value in the multi-value parameter, the outcome of the report will be as below:

如果我们在多值参数中选择多个值,则报告的结果如下:

结论 (Conclusion)

In this article, we learned to design a basic report in Report Builder, and we learned also how to use a multi-value parameter with advanced settings.

在本文中,我们学习了如何在Report Builder中设计基本报表,还学习了如何在高级设置中使用多值参数。

翻译自: https://www.sqlshack.com/using-multi-value-parameters-in-ssrs/

ssrs 级联参数

ssrs 级联参数_在SSRS中使用多值参数相关推荐

  1. java 中文参数_关于JAVA中URL传递中文参数的问题

    今天在调用一个接口时,需要传递一个中文参数,结果获取不到数据,原因就在于中文传参的编码问题. 问题来源:URL url= new URL("http://XXX?OrganName=司法厅& ...

  2. python 函数调用 不允许关键字参数_你所不知道的Python|函数参数的演进之路

    原标题:你所不知道的Python|函数参数的演进之路 函数参数处理机制是Python中一个非常重要的知识点,随着Python的演进,参数处理机制的灵活性和丰富性也在不断增加,使得我们不仅可以写出简化的 ...

  3. python怎么理解函数的参数_理解Python中函数的参数

    定义函数的时候,我们把参数的名字和位置确定下来,函数的接口定义就完成了.对于函数的调用者来说,只需要知道如何传递正确的参数,以及函数将返回什么样的值就够了,函数内部的复杂逻辑被封装起来,调用者无需了解 ...

  4. python中list作为函数参数_在python中list作函数形参,防止被实参修改的实现方法

    0.摘要 我们将一个list传入函数后,函数内部对实参修改后,形参也会随之改变.本文将主要介绍这种错误的现象.原因和解决方法. 1.代码示例 def fun(inner_lst): inner_lst ...

  5. python 实例方法调用时可以忽略第一个参数_盘点Python中易忽略的函数

    Python 内置函数 1.ord() 函数是 chr() 函数(对于8位的ASCII字符串)或 unichr() 函数(对于Unicode对象)的配对函数,它以一个字符(长度为1的字符串)作为参数, ...

  6. lstm 输入数据维度_理解Pytorch中LSTM的输入输出参数含义

    本文不会介绍LSTM的原理,具体可看如下两篇文章 Understanding LSTM Networks DeepLearning.ai学习笔记(五)序列模型 -- week1 循环序列模型 1.举个 ...

  7. java请求参数_在Java中发送http的post请求,设置请求参数等等

    前几天做了一个定时导入数据的接口,需要发送http请求,第一次做这种的需求,特地记一下子, 导包 import java.text.SimpleDateFormat; import java.util ...

  8. java 反射 不定参数_关于 Java 中的 不定参数

    简单修改 JAVA中可以使用不定参数, 例如 public void test(String ...args){...} 这里test方法可以传入参数的情况是: 1.不使用参数,如test() 2.使 ...

  9. python类的参数_在Python中使用类中的参数

    当我在Codecademy上学习 Python时,我遇到了这个问题,代码如下: class Employee(object): def __init__(self, name): self.name ...

最新文章

  1. 传输18 Gbps的HDMI 2.0,包括4 K 60 4:4:4参考设计
  2. SpringBoot报错:Could not autowire. No beans of ‘DiscussantMapper‘ type found
  3. codevs-2235
  4. 这样就算会了PHP么?-11
  5. pyspark与jupyter集成
  6. linux man手册_Linux微操(基于Centos)
  7. linux中split分割文件打开方式,Linux系统下使用split命令分割大文件 (转载)
  8. sketch文件导出没有背景色怎么办? sketch背景色消失的解决办法
  9. LaTeX的常用命令
  10. 在线html代码生成器,支持网页快速排版 CSS代码一键生成的在线设计工具
  11. 层级分类(续)-使用B-CNN(Branch CNN)实现
  12. Python数据分析基础(2)
  13. python掷骰子实验代码_Python Tkinter实例——模拟掷骰子
  14. Db2 SQL PL简介
  15. SuperSocket实战---使用SuperSocket的FixedHeaderReceiveFilter进行通信
  16. html下拉 小狗,html会动的小狗狗源码
  17. 美国核聚变反应中首次实现净能量增益 或改变未来能源路线图
  18. 本科课程【数字图像处理】实验3 - 图像的几何变换
  19. 奔跑吧,HR!RPA与人力资源自动化
  20. php上传文件到99%就没,phpexcel读文件的时候cpu99%

热门文章

  1. 谷歌chromeos_谷歌浏览器 79.0.3945.79 正式版
  2. leftjoin多了性能下降_MySQL 性能优化总结
  3. ★LeetCode(704)——二分查找(JavaScript)
  4. git由于网络原因导致 please make sure you have the correct access rights and the repository exists
  5. 【零基础学Java】—继承的概述(十九)
  6. mysql5.7 json特性_【Mysql】Mysql5.7新特性之-json存储
  7. .net解析传过来的xml_隧桥管廊BIM+GIS运维管理系统方案解析
  8. 决定要放下的人,要不要好好道个别?
  9. 住170平以上的大平层大户型什么感觉?
  10. 亲戚的孩子说要寄养在我家,上学方便,怎么明确的拒绝?