Anjali
Anjali

Reputation: 1718

How to Convert Varchar(1) to Bit in Sql Query?

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?

Upvotes: 0

Views: 1629

Answers (1)

juergen d
juergen d

Reputation: 204756

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.

Upvotes: 1

Related Questions