views:

127

answers:

2

Hello,

I am querying a database and I have 2 bit columns I need to combine (for this example if one is true the column must be true).

Something like: Select col1 || col2 from myTable

What is the easiest way of achieving this?

+2  A: 

I'm assuming col1 and col2 are bit values, the closest Sql Server has to booleans.

To return 1 or 0:

select case when col1=1 or col2=1 then 1 else 0 end
from yourtable

To return true or false:

select case when col1=1 or col2=1 then 'true' else 'false' end
from yourtable
Andomar
+5  A: 

Select col1 | col2 from myTable

http://msdn.microsoft.com/en-us/library/ms176122.aspx

Stefan Steinegger
+1 Nicely done.
Andrew Hare
Andomar