0

I have a table employee with these columns:

  • employeeID (int)
  • emp_name (varchar50)
  • JoinDate (date)
  • Salary (double(5,2))

etc.

And when I'm trying to get output in format like this: (employeeName & Salary). I was trying with this code:

SELECT emp_name + ' ' + salary As Emp_Salary 
FROM employees

but I always get an error:

Error converting data type varchar to numeric.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Blaž Čukelj
  • 83
  • 1
  • 7

1 Answers1

1

emp_name is varchar and salary is double (numeric type). You can't just concrete the differnt types into one type. You need to convert it into the same type, in this case it will be varchar. If you are comeing from script languages as javascript where the types are weak types, it will make sense, but not in SQL. You should try it like this-

CAST(salary  AS VARCHAR)
The scion
  • 1,001
  • 9
  • 19