0

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?

1
  • 1
    N=>1 is an unusual mapping. Is that really what you're looking for? (Most people would interpret N as "No", which generally maps to a false value) Commented Sep 24, 2013 at 7:28

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks juergen d, it is helpful for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.