sql server - Getting "Subquery returned more than 1 value" error running update query -
please gentle, trying update query in sql server facing error. here 2 tables in same database , query furnished below , requirement update column groupcode in table2 based on table 1 facing following error:
error
msg 512, level 16, state 1, line 1 subquery returned more 1 value. not permitted when subquery follows =, !=, <, <= , >, >= or when subquery used expression. statement has been terminated.
table 1
**dept** **deptcode** **groupname** **groupcode** 32 login-els 1 32 qc-els 4 ct 20 login-oup 1 ct 20 xml-oup 2 ct 20 qc-oup 4 mech 34 login-cen 1 mech 34 xml-cen 2 mech 34 pagination-cen 3 mech 34 qc-cen 4
table2
**activity** **deptcode** **group** login-els 32 null qc-els 32 null login-oup 20 null xml-oup 20 null qc-oup 20 null login-cen 34 null xml-cen 34 null pagination-cen 34 null qc-cen 34 null
sql
update db1..activity set groupcode = ( select groupcode db1..groups deptcode=32 , groupname = ( select activity db1..activity deptcode=32 ) )
the error message indicates 1 or both of subquery returned more 1 row. that's not allowed you're using subqueries operand of =
. 1 possible way fix error adding top 1
each of subquery.
another possible way accomplish kind of update task using update ... ... join
syntax :
update activity set groupcode = g.groupcode activity inner join groups g on a.activity = g.groupname , a.deptcode = g.deptcode a.deptcode = 32
Comments
Post a Comment