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.
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?
SQL Server does not support a Boolean type e.g. SELECT WHEN CAST(1 AS BIT) THEN 'YES' END AS result -- results in an error i.e. CAST(1 AS BIT) is not the same logical TRUE.
when passing the param as LONG to the sql script is equivalent to asking if the Boolean variable is set to true. It looks like false is 0. and from what I can tell in vs 2017, you cant "leave" a Boolean ssis variable equal to anything but true or false.
A stored procedure does not have a return value but can optionally take input, output, or input-output parameters. A stored procedure can return output through any output or input-output parameter.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With