Harish Selvaraj Harish Selvaraj - 1 year ago 75
SQL Question

SQL Server query with update error from select query

update ItinventoryR1
set iin_userid = (select emp.empid
from employee emp, itinventoryr1 it
where ltrim(rtrim(it.iin_username)) in (emp.empname))

Error is :

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

Answer Source

I guess you need something like this:

SET iin_userid = emp.empid
FROM itinventoryr1 R1
INNER JOIN employee emp
    ON ltrim(rtrim(R1.iin_username)) = emp.empname

Join tables, and update one of them.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download