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

Ramana Kopparapu 266 Reputation points
2024-02-03T07:15:02.2033333+00:00

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.
13,361 questions
{count} votes

Accepted answer
  1. Viorel 114.7K Reputation points
    2024-02-03T09:19:42.1+00:00

    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

0 additional answers

Sort by: Most helpful