存储过程返回的值如下:
Text Value
sdsd 555
dsaa 544
swewe 745
如果失败了,它会像:
一样返回Standard
No Records Fouond
如何在SQL查询级别中区分这2个结果?
注意:我无法修改存储过程
答案 0 :(得分: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