Trouble Checking a Boolean parameter

  • I'm having trouble using an If statement and checking to see if my boolean parameter is true in my stored procedure

    @Acknowledged as BOOLEAN (is my parameter)

    IF @Acknowledged = true

    BEGIN

    UPDATE ---- SET --- = getdate() WHERE ----

    END

    It doesn't seem to like me using true, whats the proper way to check for the boolean value?

    Thanks,

  • You should compare it to 1 or 0

    but the better way of doing it is to convert the 1 and 0 to a BIT type as they are INT values

    so you would say

    IF @MyVal = CONVERT(BIT, 1)

    Print 'It is true'

    It does not have a great effect on comparing 1 or 0 to a BIT variable. But when you compare it to a column value in a table then you must convert it to a BIT. If you don't and there is an index on that BIT field, then SQL may not use that index because the value you supply is of a different type.

  • Thanks Johannes!!

    That is working for me now.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply