|
Posted by Roy Harvey on 07/06/06 11:41
On Thu, 06 Jul 2006 10:46:50 +0200, R.A.M. <r_ahimsa_m@poczta.onet.pl>
wrote:
>IF EXISTS (SELECT * FROM deleted WHERE Movement IN ('PZ', 'ZW'))
> DELETE FROM PositionsPZZW
> WHERE Number IN (SELECT Number FROM deleted);
That looks dangerous. If one row in DELETED has a 'PZ' value, all
rows in PositionsPZZW that match DELETED will be dropped, even those
that do NOT have 'PZ' or 'ZW'.
How about this alternative:
DELETE FROM PositionsPZZW
WHERE Number IN
(SELECT Number FROM deleted WHERE Movement IN ('PZ', 'ZW'));
It does not require the IF test at all, as if there are no matches it
will do nothing.
Roy Harvey
Beacon Falls, CT
[Back to original message]
|