如果在t-sql中大于0,则选择true

时间:2011-06-26 12:18:56

标签: sql tsql sql-server-2008

我想执行查询,其中如果前一列中的值为0,则列为false;如果大于0则为true:

例如:

id  count
1   1
2   3
3   0
4   5
5   2

结果:

id   count
1    true
2    true
3    false
4    true
5    true

2 个答案:

答案 0 :(得分:9)

select 
    id, 
    case 
        when count > 0 then 'true'
        else 'false'
    end as count
from myTable

答案 1 :(得分:6)

select id
    , case when count > 0 then cast(1 as bit) else cast(0 as bit) end as count
from myTable