2011-07-25 37 views
0

此选择查询给我我想要修改我想更新表中的多个行,但是如果某个列的值不存在于另一个表中?

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和一如既往的支持深表感谢

回答

1

原来正被在位置表的更新触发器的查询导致该错误,所以我能够通过禁用(和一段时间后固定)触发器来解决它。谢谢所有花时间帮助我的人。

0

你可能想尝试

Update Location set DeviceAddress = NULL where Location.DeviceAddress not in (Select 
top 1 DeviceAddress From Device where Device.DeviceAddress == Location.DeviceAddress) 

在这种情况下,你的子查询将返回只值1,而不是多。

0

尝试

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