The problem occurs because you have two different data types returned from the case structure. The
Head_Type
is a bit and you're returning it in the else branch. In all other branches you're returning character data. Because there is no implicit conversion from bit to varchar you face the error
So to correct this you should explicitely convert the bit. Something like the following:
Select designation ,
(Case
when Head_Type = '0' then 'Courseofficer'
When Head_Type = '1' then 'Authorisedsignatory'
else cast(Head_Type as varchar)
end) as Type
from Designations
The next thing is that the field you compare is a bit. With bit you shouldn't use char comparison since it causes an extra conversion. So the case would be better with
Select designation ,
(Case
when Head_Type = 0 then 'Courseofficer'
When Head_Type = 1 then 'Authorisedsignatory'
else cast(Head_Type as varchar)
end) as Type
from Designations
since you're using just a single value comparison I would also simplify the case structure to
Select designation ,
(Case Head_Type
when 0 then 'Courseofficer'
When 1 then 'Authorisedsignatory'
else cast(Head_Type as varchar)
end) as Type
from Designations
Also as
Maciej Los[
^] pointed out in the first solution, the condition for the case could be simplified to use the already existing data.
As a side note The else branch handles the situation that the head_type is possibly null so you may need to adjust the code to better handle such situation...