SQL选择布尔选项

时间:2012-02-13 15:32:33

标签: sql tsql formatting boolean ssms

对于模糊的标题感到抱歉,但我不确定如何在句子中解释我想要做什么。

序言:选择布尔列的SQL语法如下:

SELECT MyBooleanColumn FROM MyTableThatHasABooleanColumn

这会产生以下结果:

MyBooleanColumn
===============
       1
       1
       1
       0
       1
      ...

问题:有没有办法获得以下结果?

MyBooleanColumn
===============
     True
     True
     True
     False
     True
      ...

3 个答案:

答案 0 :(得分:5)

SELECT case 
        when MyBooleanColumn = 1 then 'True' 
        else 'False' 
    end as MyBooleanColumn  
FROM MyTableThatHasABooleanColumn 

答案 1 :(得分:2)

是的,这样做:

SELECT 
case when MyBooleanColumn = 1 then 'True' else 'False' end as MyBooleanColumn 
FROM MyTableThatHasABooleanColumn

答案 2 :(得分:1)

SELECT case when MyBooleanColumn = 1 then 'True' else 'False' end as MyBooleanColumn  
FROM MyTableThatHasABooleanColumn