创建一个代理过程,将两个集合都放入一个临时表中,然后从中进行选择。
这是一个测试示例...
/*Create first proc that returns two data sets*/
IF OBJECT_ID('ReturningTwoDataSets') IS NOT NULL
BEGIN
DROP PROCEDURE ReturningTwoDataSets
END
GO
CREATE PROCEDURE dbo.ReturningTwoDataSets
AS
BEGIN
SET NOCOUNT ON
SELECT '1' AS [col1]
,'2' AS [col2]
,'3' AS [col3]
SELECT '4' AS [col1]
,'5' AS [col2]
,'6' AS [col3]
END
GO
/*
Create new proc that combines both data sets
into a temp table and returns a single dataset
*/
IF OBJECT_ID('ReturningOneDataSet') IS NOT NULL
BEGIN
DROP PROCEDURE ReturningOneDataSet
END
GO
CREATE PROCEDURE dbo.ReturningOneDataSet
AS
BEGIN
SET NOCOUNT ON
IF OBJECT_ID('TempDB..#OneDataSet') IS NOT NULL
BEGIN
DROP TABLE #OneDataSet
END
CREATE TABLE #OneDataSet
(
[col1] VARCHAR(100)
,[col2] VARCHAR(100)
,[col3] VARCHAR(100)
)
INSERT INTO #OneDataSet
(
col1
,col2
,col3
)
EXEC ReturningTwoDataSets
SELECT * FROM #OneDataSet
END
GO
/*Execute the old proc*/
EXEC ReturningTwoDataSets
/*Execute the new proc*/
EXEC ReturningOneDataSet