Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
select 'Economics'=(case Economics when -1 then 'Absent' Else Economics End)
from tblCOM.

the query is running with the following error


Conversion failed when converting the varchar value 'Absent' to data type int.
Posted
Comments
[no name] 6-Jul-15 9:14am    
The string "Absent" cannot be converted to an integer, obviously.
Sreekanth Mothukuru 6-Jul-15 9:40am    
what is the column "Economics" data type and can be compared with -1 ?

1 solution

It doesn't work because it isn't written in the correct mode.
You have to write in the right mode as this way:

select case when economics ='-1' then 'Absent'
else Economics end as Economics
from tblCOM

or in you case
select replace(economics,'-1','Absent') as Economics
from tblCOM
 
Share this answer
 
Comments
AmyAli 7-Jul-15 11:40am    
Thanks a lot the Second one is working accordingly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900