2014-03-25 44 views
4

我想這樣做,但存儲過程的結果:SQL服務器的測試結果

select * from table where column=whatever 
except 
select * from table2 where column=whatever 

所以

exec sp1 args 
except 
exec sp2 args 

我的SPS沒有返回值,他們只取參數和返回選擇語句的結果

+3

你可以用你的SP填充臨時表,或者使用表值函數或視圖。 –

+0

sps我不能改變,但我可以給臨時表一個去 –

回答

4

給出這個結果。

CREATE PROCEDURE usp_sp1_Except_sp2 
@sp1 args  --<-- All the params sp1 Expects 
@sp2 args  --<-- All the params sp2 Expects 
AS 
BEGIN 
    SET NOCOUNT ON; 

IF OBJECT_ID('tempdb..#SP1_Results') IS NOT NULL 
DROP TABLE #SP1_Results 

IF OBJECT_ID('tempdb..#SP2_Results') IS NOT NULL 
DROP TABLE #SP2_Results 


CREATE TABLE #SP1_Results 
(
    -- Define table structure here 
) 

CREATE TABLE #SP2_Results 
(
    -- Define table structure here 
) 


INSERT INTO #SP1_Results 
EXECUTE dbo.sp1 @sp1 

INSERT INTO #SP2_Results 
EXECUTE dbo.sp2 @sp2 

SELECT * FROM #SP1_Results 
EXCEPT 
SELECT * FROM #SP2_Results 

    SET NOCOUNT OFF; 

END