我正在尝试将值写入输出参数。在我的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
答案 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