简体   繁体   English

基于先前参数的SSRS参数

[英]SSRS parameters based on previous parameter

In my report I have a parameter which allows the user to choose one or multi-options. 在我的报告中,我有一个参数,允许用户选择一个或多个选项。

Driver 1,
Driver 2,
Driver 3

I have another parameter that would only be valid if they chose Driver 3 from the previous parameter. 我有另一个参数,只有在他们从上一个参数中选择了Driver 3时,该参数才有效。

AAA,
BBB,
CCC

So maybe the user would choose Driver 1 and Driver 3 and then choose BBB. 因此,也许用户会选择驱动程序1和驱动程序3,然后选择BBB。 How can I have the report provide all the data for Driver 1 and only BBB for Driver 3? 如何让报告提供驱动程序1的所有数据,而仅提供驱动程序3的BBB?

Are the lists of parameter values coming from the database? 参数值列表是否来自数据库? If so you can use the result of the first parameter to filter the query for the second. 如果是这样,您可以使用第一个参数的结果来过滤第二个查询。 For example. 例如。 If we wanted to be able to select from a list of geographical regions and then from there choose from a list of countries that exist in those regions we could do something like this. 如果我们希望能够从地理区域列表中进行选择,然后从那里选择那些区域中存在的国家/地区,那么我们可以做这样的事情。

Create a new dataset called say dsRegions and get a list of regions from the database with something like 创建一个名为say dsRegions的新数据集,并从数据库中获取诸如以下内容的区域列表

SELECT RegionID, RegionName From dbo.Regions

Create a new parameter @regions and set it to be multi-value and set the available values to be from a dataset. 创建一个新参数@regions并将其设置为多值,并将可用值设置为来自数据集。 select dsRegions and use the ID column as the value and name column as the label. 选择dsRegions,然后将ID列用作值,并将name列用作标签。

Create another dataset say dsCountries but this time the query will look something like this. 创建另一个名为dsCountries的数据集,但是这次查询将看起来像这样。

SELECT CountryID, CountryName FROM dbo.Countries WHERE RegionID IN (@regions)

Note: It is important to use IN (@regions) and not = @regions or the query will fail when more than one region is selected. 注意:重要的是使用IN(@regions)而不是= @regions,否则当选择多个区域时查询将失败。

Create a new parameter @countries, set it up as we did with the previous parameter but this time pointing it at dsCountries 创建一个新参数@countries,与上一个参数一样进行设置,但是这次将其指向dsCountries

This way, anytime the user selects a new region or regions, the @regions parameter is updated, then the countries list will be re-queried and populated. 这样,无论何时用户选择一个或多个新区域,@regions参数都会更新,然后将重新查询并填充国家列表。

Finally, the @countries parameter would be passed to the main dataset for the report. 最后,@ countries参数将传递到报表的主数据集。

Assuming your 1st and 2nd parameters have a similar relationship then you should be able to adapt this generic example easily. 假设您的第一个和第二个参数具有相似的关系,那么您应该能够轻松地适应这个通用示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM