stack stack - 3 months ago 11
SQL Question

Combining column name is giving 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 error as


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