Помогите понять в чем ошибка запроса на удаление?

Dougy
Дата: 23.01.2013 14:36:02
Относительно простой запрос на удаление выдает ошибки:

delete from Fr_Gar_Sostav1 f1 where f1.InventoryID not in (select f2.InventoryOwnerID from Fr_Gar_Sostav1 f2 where f2.Cat=28) and f1.Cat=28

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'f1'.
Server: Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'and'.

При этом выборка работает без проблем:


select * from Fr_Gar_Sostav1 f1 where f1.InventoryID not in (select f2.InventoryOwnerID from Fr_Gar_Sostav1 f2 where f2.Cat=28) and f1.Cat=28

Помогите понять, что не так, заранее спасибо:)
Glory
Дата: 23.01.2013 14:38:31
delete f1 from Fr_Gar_Sostav1 f1 where f1.InventoryID not in (select f2.InventoryOwnerID from Fr_Gar_Sostav1 f2 where f2.Cat=28) and f1.Cat=28
Cygapb-007
Дата: 23.01.2013 14:39:20
Dougy
Относительно простой запрос на удаление выдает ошибки:

delete from Fr_Gar_Sostav1 f1 where f1.InventoryID not in (select f2.InventoryOwnerID from Fr_Gar_Sostav1 f2 where f2.Cat=28) and f1.Cat=28

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'f1'.
Server: Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'and'.

При этом выборка работает без проблем:


select * from Fr_Gar_Sostav1 f1 where f1.InventoryID not in (select f2.InventoryOwnerID from Fr_Gar_Sostav1 f2 where f2.Cat=28) and f1.Cat=28

Помогите понять, что не так, заранее спасибо:)
Может попробовать так:
--select *
delete f1
from Fr_Gar_Sostav1 f1 where f1.InventoryID not in (select f2.InventoryOwnerID from Fr_Gar_Sostav1 f2 where f2.Cat=28) and f1.Cat=28
Dougy
Дата: 23.01.2013 14:39:39
Спасибо большое! заработало:)
iap
Дата: 23.01.2013 14:41:09
Алиасы могут объявляться только во FROM и MERGE
DELETE f1
FROM Fr_Gar_Sostav1 f1
WHERE f1.Cat=28
AND NOT EXISTS(SELECT * FROM Fr_Gar_Sostav1 f2 where f2.Cat=28 AND f2.InventoryOwnerID=f1.InventoryID);
Но это не тот FROM, который сразу после DELETE!
iap
Дата: 23.01.2013 14:44:51
Dougy
Спасибо большое! заработало:)
Ж)))Осторожней с NOT IN()
Лучше NOT EXISTS()
iap
Дата: 23.01.2013 14:46:26
Что-то тег изуродовался :((

Dougy
Спасибо большое! заработало:)
Осторожней с NOT IN()
Лучше NOT EXISTS()
Dougy
Дата: 23.01.2013 14:48:53
Хорошо, спасибо за совет:)