stack stack - 3 months ago 9
SQL Question

Combining column name is causing error

I have two columns which I want to combine and show the data, I tried like below

select
case
when status = 'R'
then 'Resign'
when status = 'A'
then 'Active'
end as status1,
Program_name + ' ' + emp_card_no as program_details,
*
from
GetEmployeeDetails
where
emp_name = 'ABHAY ASHOK MANE'
and STATUS = 'A'
order by
EMP_NAME


but I am getting an error:


Error converting data type varchar to numeric.


Here is the sample data available

img

Answer

Try this :

select 
  case when status='R' then 'Resign'
       when status='A' then 'Active' 
  end as status1, 
  Program_name + ' (' + convert(varchar, emp_card_no) + ') ' as program_details,
* 
from GetEmployeeDetails
Where emp_name ='ABHAY ASHOK MANE'and STATUS= 'A' ORDER BY EMP_NAME
Comments