I'm trying to work out how to write a store procdure which returns a boolean value. I started off writing the following one which returns an int.
我正在尝试研究如何编写一个返回布尔值的store procdure。我开始写下面的一个返回一个int。
USE [Database]
GO
/****** Object: StoredProcedure [dbo].[ReturnInt] Script Date: 09/30/2010 09:31:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[ReturnInt] AS
RETURN 3
I'm unsure however how to write one to return a boolean value.
我不确定如何写一个返回一个布尔值。
Can somebody help? Is it a bit value?
有人可以帮忙吗?它有点价值吗?
3 个解决方案
#1
30
You can't. There is no boolean datatype and the procedure return code can only be an int
. You can return a bit
as an output parameter though.
你不能。没有布尔数据类型,并且过程返回代码只能是int。您可以返回一点作为输出参数。
CREATE PROCEDURE [dbo].[ReturnBit]
@bit BIT OUTPUT
AS
BEGIN
SET @bit = 1
END
And to call it
并称之为
DECLARE @B BIT
EXEC [dbo].[ReturnBit] @B OUTPUT
SELECT @B
#2
17
Use this:
用这个:
SELECT CAST(1 AS BIT)
选择CAST(1个位)
#3
1
You have at least 2 options:
您至少有两个选择:
SELECT CONVERT(bit, 1)
SELECT CAST(1 AS bit)
#1
30
You can't. There is no boolean datatype and the procedure return code can only be an int
. You can return a bit
as an output parameter though.
你不能。没有布尔数据类型,并且过程返回代码只能是int。您可以返回一点作为输出参数。
CREATE PROCEDURE [dbo].[ReturnBit]
@bit BIT OUTPUT
AS
BEGIN
SET @bit = 1
END
And to call it
并称之为
DECLARE @B BIT
EXEC [dbo].[ReturnBit] @B OUTPUT
SELECT @B
#2
17
Use this:
用这个:
SELECT CAST(1 AS BIT)
选择CAST(1个位)
#3
1
You have at least 2 options:
您至少有两个选择:
SELECT CONVERT(bit, 1)
SELECT CAST(1 AS bit)