如何组合2位列

Ser*_*gio 11 sql t-sql sql-server

我正在查询数据库,并且我需要组合2位列(对于此示例,如果一个为真,则列必须为true).

就像是: Select col1 || col2 from myTable

实现这一目标的最简单方法是什么?

And*_*mar 5

我假设col1和col2是位值,最接近的Sql Server必须是布尔值.

要返回1或0:

select case when col1=1 or col2=1 then 1 else 0 end
from yourtable
Run Code Online (Sandbox Code Playgroud)

要返回true或false:

select case when col1=1 or col2=1 then 'true' else 'false' end
from yourtable
Run Code Online (Sandbox Code Playgroud)