Skip to content
Advertisement

How to convert a varchar column to bit column in SQL SERVER

Flag1 is a varchar column with values “true” and “false”. I need to convert this into bit column.

When I try to do this:

it shows an error

Advertisement

Answer

I suspect that there are other values in addition to ‘true’ and ‘false’ in the field ‘Flag1’. So check for the values in Flag1.

select distinct Flag1 from YouTable.

Here is my proof:

It works fine.

However, this will give the same error.

-> Msg 245, Level 16, State 1, Line 2 Conversion failed when converting the varchar value ‘ False’ to data type bit.

Pay attention to the the space in ‘ False’ in the error message!

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement