简体   繁体   English

如何基于2个数据源过滤SSRS报告

[英]How to filter a SSRS report based on 2 datasources

I have created a stored proc where I have data coming from 2 data sources. 我创建了一个存储过程,其中有来自2个数据源的数据。 I have created a Union between source A and source B and then feeding this as a dataset to the SSRS report. 我在源A和源B之间创建了一个并集,然后将其作为数据集提供给SSRS报告。 Now the user wants to see the report based on a source parameter which will give them the ability to select/filter the report based on the data sources either "source A", "source B" or "both". 现在,用户希望基于源参数查看报告,这将使他们能够基于“源A”,“源B”或“两者”的数据源选择/过滤报告。 So if user selects source A , then report should show data from source A only and if "both" then it will show results from both source A and source B. 因此,如果用户选择来源A,则报告应仅显示来源A的数据,如果报告“两者”,则报告将同时显示来源A和来源B的结果。

One way , I am trying to tackle this problem is creating 3 separate data sets and then using a parameter. 一种方法是,我尝试解决此问题的方法是创建3个单独的数据集,然后使用参数。 I am not sure if that's the best design approach. 我不确定这是否是最佳设计方法。 Please share if anyone has any better ideas. 如果有人有更好的主意,请分享。

Thanks in Advance ! 提前致谢 !

You could simply tag an extra column onto your query with the source identified something like 您可以简单地在查询中标记一个额外的列,其中源标识为类似

SELECT *, 'A' as Src FROM myFirstDataSource
UNION
SELECT *, 'B' as Src FROM mySecondDataSource

Then just apply a filter on the Src column. 然后,只需在Src列上应用过滤器即可。

Alternatively just do this in the SP itself by passing a parameter in from the report to determine what data to fetch, something like. 或者,只需在SP本身中执行此操作,方法是从报表中传入一个参数,以确定要提取的数据,例如。

CREATE PROC myProc (@myParam varchar(1) = '') AS
DECLARE @t TABLE (Src varchar(1), ColumnA varchar(10), ColumnB int, ColumnC int)

IF (@myParam = '' OR @myParam = 'A')
    BEGIN -- get data from first datasource
        INSERT INTO @t
        SELECT 'A', someCOlumnA, SomeColumnB, SomeColumnC FROM myFirstDataSource
    END

IF (@myParam = '' OR @myParam = 'B')
    BEGIN -- get data from second datasource
        INSERT INTO @t
        SELECT 'B', someCOlumnA, SomeColumnB, SomeColumnC FROM mySecondDataSource
    END

SELECT * FROM @t

You don't really need the Src column in the second option but it might be useful in case you want to highlight where data comes from in the report. 您实际上并不需要第二个选项中的Src列,但是如果您想突出显示数据在报表中的位置,它可能会很有用。

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

相关问题 根据临时表运行SSRS报告 - Run SSRS report based on temporary table 如何为查询生成报告表[SSRS],该表根据参数返回不同的列 - How to Generate Report table [SSRS] for the Query which returns different columns based on parameters 基于参数隐藏SSRS中的子报告(并且不执行存储过程) - Hiding Sub report in SSRS based on Parameter (and not executing the Stored Procedure) 如何指定要在SSRS报告向导中使用的存储过程? - How can I specify a Stored Procedure to be used in the SSRS Report Wizard? 在ssrs中单击“查看报告”时如何立即运行程序? - How to run a procedure immediately when 'view report' is clicked in ssrs? 为什么基于存储过程的SSRS报告在几秒钟内返回结果就会超时? - Why does a SSRS report time out when the Stored Procedure it is based on returns results within a few seconds? 如何从“基本” SSRS报告向辅助报告提供报告参数? - How can I supply report parameters to ancillary reports from a “base” SSRS report? 使用存储过程的SSRS报告 - SSRS Report Using Stored Procedure 查询SSRS报告的存储过程 - Query to Stored Procedure for SSRS Report SSRS中的渲染部件异步报告 - Render parts in SSRS report asynchronously
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM