0

存储过程返回的值如下:

Text       Value
sdsd         555
dsaa         544
swewe        745

如果它失败了,它会像这样返回:

Standard
No Records Fouond

如何在 SQL 查询级别区分这 2 个结果?

注意:我不能修改存储过程

4

1 回答 1

0

使用 proc 的输出来找出答案。

    IF EXISTS(
                SELECT name 
                FROM sysobjects 
                WHERE  name = N'Pr_Test' 
                AND type = 'P' )
    DROP PROCEDURE Pr_Test
    GO
    Create Procedure Pr_Test
    (
        @output BIT=0
    )
    As
    BEGIN  
    SET NOCOUNT ON  

        IF @output = 0
            SELECT 'No Records Fouond' AS [STANDARD]
        ELSE
            SELECT 'abc' AS [text], 1 AS [VALUE]

    SET NOCOUNT OFF  
    END  
    Go

    SET NOCOUNT ON
        DECLARE @ProcOutput TABLE 
        (
            column1     sysname NOT NULL
        )


        INSERT INTO @ProcOutput(Column1)
        EXEC Pr_Test

        IF EXISTS (SELECT TOP 1 1 FROM @ProcOutput WHERE column1='No Records Fouond')
            PRINT ' this is failed select from proc'
        ELSE
            PRINT 'proc has some results'
    SET NOCOUNT OFF
于 2013-10-22T15:52:33.940 回答