January 20, 2019 at 10:00 am
I created a simple function that checks a given string and return a value of BIT type. The script of this function is attached.
When I was trying to use this function in following IF statement, I got error of "an expression of non-boolean type specified in a context where a condition is expected". The function clearly returns a BIT value, which is considered as boolean. Why the IF statement failed?
-------------------------------------------------------------------------
IF (dbo.fn_IsQueryFilter(@InParam))
PRINT 'has input'
ELSE
PRINT 'no input value'
-------------------------------------------------------------------------
I also did another test with following script. I got exact same error shown above. When did I do wrong in these two scripts?
DECLARE @yn bit
SELECT @yn = 1
IF (@yn)
PRINT 'is true'
January 20, 2019 at 10:14 am
You have to do it the long-winded way;
If (condition) = 1
Begin
End
January 20, 2019 at 10:39 am
yyang4 - Sunday, January 20, 2019 10:00 AMI created a simple function that checks a given string and return a value of BIT type. The script of this function is attached.
When I was trying to use this function in following IF statement, I got error of "an expression of non-boolean type specified in a context where a condition is expected". The function clearly returns a BIT value, which is considered as boolean. Why the IF statement failed?
-------------------------------------------------------------------------
IF (dbo.fn_IsQueryFilter(@InParam))
PRINT 'has input'
ELSE
PRINT 'no input value'
-------------------------------------------------------------------------
I also did another test with following script. I got exact same error shown above. When did I do wrong in these two scripts?
DECLARE @yn bit
SELECT @yn = 1
IF (@yn)
PRINT 'is true'
There isn't a boolean data type in SQL Server and BIT is not boolean. You need to specify the condition:
IF dbo.fn_IsQueryFilter(@InParam) = 1
PRINT 'true'
ELSE
PRINT 'false'
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy