views:

1130

answers:

1

I want to use a computed bit column that will be true if another column in the table is not null. What's the correct formula for this?

HasLabel = computed column (bit)
Label = varchar NULL

The following formula does not validate - what am I missing?
Formula for HasLabel = Label IS NOT NULL

+11  A: 

A computed column must return a value, whereas you are just doing a comparison. Try this instead:

case when label is null then 0 else 1 end

SQL Server will not understand this as a non-NULLable column however. To handle that, change the computation to:

isnull(case when label IS NULL then 0 else 1 end, 0)
RedFilter