How to use Multiple result sets in Reporting Services

十年热恋 提交于 2019-12-08 03:54:47

问题


I have a stored procedure which returns multiple result sets similiar to the following:

ALTER PROCEDURE sp_XXXX 
(
    XXXXXX
)
AS
SET NOCOUNT ON

SELECT XXXXXXX    


IF @@ROWCOUNT = 0
    SELECT     XXXXXXX



RETURN

I want my report to use the first result set if it has data or use the second one in case the first one is empty. Any help?


回答1:


In the sproc "union all" your two result sets. If you need to tell them apart add a derived column indicating the original result set.

select 'ds1' as dataset, *
from table1
union all
select 'ds2' as dataset, *
from table2

Another try

Dump result set 1 into a temp table and only execute the second query if it's empty.

pseudo code:

select * into #tempResult 
from table 1

if table1 is empty 

select * from table2


来源:https://stackoverflow.com/questions/567141/how-to-use-multiple-result-sets-in-reporting-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!