2009-05-04 49 views
10

我正在查詢數據庫,並且我需要組合2位列(對於此示例,如果一個爲true,則列必須爲true)。如何組合2位列

是這樣的:Select col1 || col2 from myTable

什麼是實現這一目標的最簡單的方法?

回答

5

我假設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