How to convert CHAR(1) to BIT in SQL SERVER

Ramana Kopparapu 206 Reputation points

Hi, I have two tables emp_source and emp_target. In Source I have 3 columns id INT Name VARCHAR(20) Gender CHAR(1) Target Table: Id INT Name VARCHAR(20) Gender BIT Assuming if Gender is 'M' which is equal to 1 and Gender is 'F' which is equal to 0 While trying to load data to Target table using MERGE Statement getting the error. Conversion failed when converting the varchar value 'M' to data type bit.. Could anyone please look into this and respond?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,286 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 109.9K Reputation points

    Try this expression: case Gender when 'M' then 1 when 'F' then 0 end. Use it in the corresponding parts of MERGE, or show details.

    1 person found this answer helpful.
    0 comments No comments