如何组合2位列
问题描述:
我正在查询数据库,并且我需要组合2位列(对于此示例,如果一个为true,则列必须为true)。如何组合2位列
是这样的:Select col1 || col2 from myTable
什么是实现这一目标的最简单的方法?
答
我假设col1和col2是比特值,最接近的Sql Server有布尔值。
要返回1或0:
select case when col1=1 or col2=1 then 1 else 0 end
from yourtable
要返回true或false:
select case when col1=1 or col2=1 then 'true' else 'false' end
from yourtable
呵呵不错。尽管我试图避免按位运算符。 |按预期工作,但是可能会造成混淆,例如“select 1&2”返回“0”。 – Andomar 2009-05-04 10:33:31