2011-07-25 38 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) 
相關問題