Select a bit with a null value with a default value

I need to select a column with a zero bit in the view, but use the default value of FALSE when the value is NULL. (For other reasons, I cannot add a default value to the source table). That's what I'm doing.

CAST ( CASE WHEN bit_column IS NULL THEN 0 ELSE bit_column END AS BIT ) AS bit_column, ... 

I have to do this on four columns, so I'm wondering if there is a better / more efficient way to do this.

+6
sql tsql bit sql-server-2000
source share
3 answers

use the isnull function.

 isnull(bit_column, 0) 
+9
source share
 SELECT coalesce(bit_column,0) bit_column 
+5
source share

Take a look at Coalesce

0
source share

All Articles