Tsql 我想更新一个表中的多行,但如果某一列的值不存在于另一个表中?

Tsql 我想更新一个表中的多行,但如果某一列的值不存在于另一个表中?,tsql,where-clause,Tsql,Where Clause,此select查询为我提供了要修改的列 Select * From Location where Location.DeviceAddress not in (Select DeviceAddress From Device) order by DeviceAddress desc 但是,此更新查询 Update Location set DeviceAddress = NULL where Location.DeviceAddress not in (Select DeviceAddr

此select查询为我提供了要修改的列

Select * From Location 
where Location.DeviceAddress not in (Select DeviceAddress From Device)  order by DeviceAddress desc
但是,此更新查询

Update Location 
set DeviceAddress = NULL
where Location.DeviceAddress not in (Select DeviceAddress From Device)
给我以下错误:

子查询返回了多个值。当子查询在=、!=、=或者当子查询用作表达式时。 声明已终止

作为参考,我使用的是Microsoft Server 2008,一如既往,非常感谢您的帮助

 Update Location set DeviceAddress = NULL where Location.DeviceAddress not in (Select 
 top 1 DeviceAddress From Device where Device.DeviceAddress == Location.DeviceAddress)
在这种情况下,子查询将只返回1个值,而不是多个值。

请重试

Update 
  Location 
set 
  DeviceAddress = NULL
where 
  not exists (Select null From Device where Device.DeviceAddress = Location.DeviceAddress)

原来这个错误是由位置表上的更新触发器中的查询引起的,所以我可以通过禁用(并在一段时间后修复)触发器来解决它。感谢所有花时间帮助我的人