我正在尝试创建一个新的 SSRS 报告,该报告将返回并显示 SQL Server 存储过程的值。我将向存储过程传递一个参数@clientID
。此参数用在 3 个不同的 BEGIN
/END
语句中。每个 BEGIN
`END` 语句都会获取参数并进行查询,返回特定数据。
当我创建 SSRS 报告时,我将数据源指向此存储过程,但仅返回第一个 BEGIN
/END
语句的结果集。如果我在 SSMS 中运行存储过程,我会得到 3 个不同的结果集,正如预期的那样。
如何将这 3 个 BEGIN
/END
结果集放入单个报告中?
示例代码:
CREATE PROCEDURE pClientData (@clientID varchar(30))
AS
DECLARE @Orders table (
...
);
DECLARE @Results table (
...
);
DECLARE @Status table (
...
);
BEGIN
SET NOCOUNT ON;
-- Get all the orders by client
INSERT INTO @Orders
SELECT ...
-- Return the results --
SELECT *
FROM @Orders;
END
BEGIN
SET NOCOUNT ON;
-- Determine the Results
INSERT INTO @Results
SELECT ...
SELECT *
FROM @Results;
END
BEGIN
SET NOCOUNT ON;
SET @Status = (
SELECT ...
);
SELECT @Status as Status;
END
GO
来自 SSRS 的查询调用:
EXEC pClientData @clientID
最佳答案
不幸的是,这是不可能的。
根据书Applied Microsoft SQL Server 2008 Reporting Services
来自 第 4.3.5 节 - 使用存储过程
:
If a stored procedure returns multiple rowsets (executes multiple
SELECT
statements), only the first rowset is processed by the report. If you need all results, consider implementing a wrapper stored procedure that merges the multiple rowsets in a temporary table and returns all rows with oneSELECT
statement.
正如建议的,您必须对存储过程进行某种调整才能完成此任务。创建一个包装器以返回单个集合中的所有结果,或者将现有存储过程拆分为三个。
Note: At the moment, you can get a pdf of the ebook here, but it might get taken down.
关于sql-server - SSRS - 在一个存储过程中返回多个查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9727123/