开发者

SQL: show description in text instead of bit value

开发者 https://www.devze.com 2023-02-06 08:00 出处:网络
I have an attribute declared as bit: (true or false). For example: SELECT myBit FROM [table] => it will show: 1 or 0

I have an attribute declared as bit: (true or false).

For example:

SELECT myBit FROM [table] 

=> it will show: 1 or 0

I would like to show: 'Valid' and 'Invalid' for 1 and 0 r开发者_JAVA百科espectively.

How could I add IF ELSE statement in the SELECT statement?


For SQL Server, you can use a CASE statement:

SELECT CASE myBit WHEN 1 THEN 'Valid' WHEN 0 THEN 'Invalid' END As MyColumn
FROM [table] 
0

精彩评论

暂无评论...
验证码 换一张
取 消