[英]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.