具有选择查询的更新错误的SQL Server查询

时间:2016-08-05 06:35:14

标签: sql sql-server

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

错误是:

  

子查询返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。

2 个答案:

答案 0 :(得分:1)

我猜你需要这样的东西:

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

加入表格并更新其中一个表格。

答案 1 :(得分:1)

试试这个

update t1 
set t1.iin_userid =t2.emp_id
from ItinventoryR1 as t1 inner join employee emp as t2
on ltrim(rtrim(t1.iin_username))=t2.empname