March 16, 2011

SQL Server: Return Boolean from Stored Procedure

Sometimes you may need to return a Boolean value from a SQL Server stored procedure. This article explains how to do so.

Create a sample procedure with an output parameter of the ‘bit’ datatype. The supported datatype of boolean in SQL Server is bit.


Here's the same code for you to try out:

@date datetime,
@status bit output
IF @date<GETDATE()
SET @status=1
SET @status=0

The above stored procedure will return 1 if the date value passed to the parameter is less than the current date and time, otherwise it will return 0.

DECLARE @date date, @b bit
SET @date='20081101'
EXEC test @date,@b output





DECLARE @date date, @b bit
SET @date='20110419'
EXEC test @date,@b output



The first code returns 1 and second code returns 0. @bit is of type bit and it receives output from the stored procedure.

Did you like this post?
kick it on
subscribe via rss subscribe via e-mail
print this post follow me on twitter

About The Author

Madhivanan,an MSc computer Science graduate from Chennai-India, works as a works as a Lead Subject Matter Expert at a company that simplifies BIG data. He started his career as a developer working with Visual Basic 6.0, SQL Server 2000 and Crystal Report 8. As years went by, he started working more on writing queries in SQL Server. He now has good level of knowledge in SQLServer, Oracle, MySQL and PostgreSQL as well. He is also one of the leading posters at and a moderator at His T-sql blog is at



0 Responses to "SQL Server: Return Boolean from Stored Procedure"

Copyright © 2009-2014 All Rights Reserved for by Suprotim Agarwal | Terms and Conditions