I would like to perform query in which as a result I have column with false if the value in former column is 0 and true if is greater then 0:
as example:
id count
1 1
2 3
3 0
4 5
5 2
result:
id count
1 true
2 true
3 false
4 true
5 true
If you are checking conditions against multiple variables then you would have to go for multiple IF Statements, Each block of code will be executed independently from other blocks. ELSE IF(@ID IS NOT NULL AND @ID in (SELECT ID FROM Places)) -- Outer Most Block ELSE IF BEGIN SELECT @MyName = Name ... ...
Answers. True or False are not reserved in SQL. Most often when programming you would use a bit and 0 = False while 1 = True.
You can use the > operator in SQL to test for an expression greater than. In this example, the SELECT statement would return all rows from the customers table where the customer_id is greater than 6000.
select
id,
case
when count > 0 then 'true'
else 'false'
end as count
from myTable
select id
, case when count > 0 then cast(1 as bit) else cast(0 as bit) end as count
from myTable
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