Share via

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

Ramana Kopparapu 306 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 | Other
{count} votes

Answer accepted by question author
  1. Viorel 126.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

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.