سؤال

I want to convert a varchar(1) to bit (True or False) or (0,1).

For example if varchar(1) value is 'N' means it should be convert to '1' else it should be convert to '0'.

Is it possible in SQL?

هل كانت مفيدة؟

المحلول

Use a case

select case when your_varchar_column = 'N' 
            then 1 
            else 0 
       end as your_bool_result
from your_table

Depending on your SQL engine you could also use an if statement if available.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top