Reputation: 4085
I was creating a function that returns BIT, I tried to "Return @count < 1", that did not work, how to convert boolean to BIT in TSQL.
Thanks
Upvotes: 3
Views: 1339
Reputation: 15816
Or a simple transmogrification of Shark's answer:
return case
when @Count < 1 then 1
else 0
end
Note that a CASE may have as many WHEN clauses as you need.
Trivia: Curiously, a BIT can be set to 'TRUE' or 'FALSE'. Yeah, quoted strings. Go figure.
Upvotes: 1
Reputation: 432210
Can count ever be negative? And count should be integer
So what you want is "1 if @COUNT = zero, zero otherwise"
RETURN 1 - SIGN(@COUNT)
Upvotes: 3
Reputation:
You will need to have a conditional statement:
if @count < 1
return 1
else
return 0
Or you could use a CASE
statement:
case
when @count < 1 then return 1
else return 0
end
Upvotes: 3