简体   繁体   中英

SQL Server query help needed

When I try the following query, zero rows are affected. Can someone help me to fix this?

UPDATE PLAN 
SET PLANID = (SELECT PLANID FROM MODE WHERE [NAME]='Sam')
WHERE CUSTOMERID IN (SELECT CUSTOMERID FROM ENTITYCUSTOMER WHERE EMPID = 707)

(SELECT PLANID FROM MODE WHERE [NAME]='Sam') will return a single code

(SELECT CUSTOMERID FROM ENTITYCUSTOMER WHERE EMPID = 707) may return multiple values.

Please help need a solution for this. Thanks

SELECT PLANID FROM MODE WHERE [NAME]='Sam'

The 'MODE' table must not be keyed on PLANID; so it can't bind a specific value to the update. One option is to create a cursor, and read the correct value with which to update. Another is to do this in whatever client code language you are using (presumably a .net langugage?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM