I want to update multiple rows in a table but iff the value of a certain column does not exist in a different table?
This select query give me the columns I want to modify
Select * From Location
where Location.DeviceAddress not in (Select DeviceAddress From Device) order by DeviceAddress开发者_运维技巧 desc
However, this update query
Update Location
set DeviceAddress = NULL
where Location.DeviceAddress not in (Select DeviceAddress From Device)
Gives me the following error:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. The statement has been terminated.
For reference I am using Microsoft Server 2008 , and, as always, assistance is much appreciated
Turns out this error was being caused by a query in an update trigger on the Location table so I was able to solve it by disabling (and after some time fixing) the trigger. Thank you to all who took the time to help me.
you might want to try
Update Location set DeviceAddress = NULL where Location.DeviceAddress not in (Select
top 1 DeviceAddress From Device where Device.DeviceAddress == Location.DeviceAddress)
in this case your subquery will return only 1 value instead of multiple.
try
Update
Location
set
DeviceAddress = NULL
where
not exists (Select null From Device where Device.DeviceAddress = Location.DeviceAddress)
精彩评论