troubleshooting Question

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

Avatar of TraciShultz
TraciShultzFlag for United States of America asked on
Microsoft SQL Server
3 Comments1 Solution2007 ViewsLast Modified:
I am trying to update multiple records and multiple fields at the same time. The correct data is being returned if I just query it but for some reason the UPDATE command does not like it. I should be able to update multiple records at the same time?

When I execute the following SLQ I get
"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression."

The SQL statement Looks like :
CREATE PROCEDURE RunXML_UpateTempMasterRackMap AS

Update TempMasterRackMap
SET Row = (SELECT dbo.TempMasterDeviceTubes.DestRackRow FROM dbo.TempMasterRackMap INNER JOIN
           dbo.TempMasterDeviceTubes ON dbo.TempMasterRackMap.bc = dbo.TempMasterDeviceTubes.bc
           WHERE (dbo.TempMasterRackMap.Row <> dbo.TempMasterDeviceTubes.DestRackRow) OR
           (dbo.TempMasterRackMap.Col <> dbo.TempMasterDeviceTubes.DestRackColumn) OR
           (dbo.TempMasterRackMap.RackBc <> dbo.TempMasterDeviceTubes.DestRackBc)),

         Col = (SELECT dbo.TempMasterDeviceTubes.DestRackColumn FROM dbo.TempMasterRackMap INNER JOIN
           dbo.TempMasterDeviceTubes ON dbo.TempMasterRackMap.bc = dbo.TempMasterDeviceTubes.bc
           WHERE (dbo.TempMasterRackMap.Row <> dbo.TempMasterDeviceTubes.DestRackRow) OR
           (dbo.TempMasterRackMap.Col <> dbo.TempMasterDeviceTubes.DestRackColumn) OR
           (dbo.TempMasterRackMap.RackBc <> dbo.TempMasterDeviceTubes.DestRackBc)),

          RackBc = (SELECT dbo.TempMasterDeviceTubes.DestRackBc FROM dbo.TempMasterRackMap INNER JOIN
           dbo.TempMasterDeviceTubes ON dbo.TempMasterRackMap.bc = dbo.TempMasterDeviceTubes.bc
           WHERE (dbo.TempMasterRackMap.Row <> dbo.TempMasterDeviceTubes.DestRackRow) OR
           (dbo.TempMasterRackMap.Col <> dbo.TempMasterDeviceTubes.DestRackColumn) OR
           (dbo.TempMasterRackMap.RackBc <> dbo.TempMasterDeviceTubes.DestRackBc))

WHERE EXISTS ((SELECT *  FROM dbo.TempMasterRackMap INNER JOIN
           dbo.TempMasterDeviceTubes ON dbo.TempMasterRackMap.bc = dbo.TempMasterDeviceTubes.bc
           WHERE (dbo.TempMasterRackMap.Row <> dbo.TempMasterDeviceTubes.DestRackRow) OR
           (dbo.TempMasterRackMap.Col <> dbo.TempMasterDeviceTubes.DestRackColumn) OR
           (dbo.TempMasterRackMap.RackBc <> dbo.TempMasterDeviceTubes.DestRackBc)))
GO
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros