存储过程的输出参数

时间:2019-08-20 19:42:31

标签: sql-server tsql stored-procedures

我正在尝试将值写入输出参数。在我的THEN语句中,我想将outParam返回为1或0,但不确定如何修改以下语句来做到这一点。有人可以帮忙吗?谢谢!

CREATE PROCEDURE [dbo].[myProc] 
     @var1 UNIQUEIDENTIFIER, 
     @outParam BIT OUTPUT
AS
    SELECT 
        CASE
           WHEN EXISTS (SELECT 1
                        FROM [Table1] AS [i]
                        WHERE (CONVERT(VARCHAR(36), [i].[var1]) = @var1) 
                          AND ([i].[BitColumn] = 1))
              THEN CAST(1 AS BIT) 
              ELSE CAST(0 AS BIT)
        END
GO

1 个答案:

答案 0 :(得分:3)

您是如此亲密!只需进行设置即可。

CREATE PROCEDURE [dbo].[myProc] @var1 uniqueidentifier, 
@outParam bit OUTPUT
AS
SELECT @outParam = CASE
    WHEN EXISTS (
        SELECT 1
        FROM [Table1] AS [i]
        WHERE (CONVERT(VARCHAR(36), [i].[var1]) = @var1) AND ([i].[BitColumn] = 1))
    THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT)
    END;
GO