我必须使用@flow从主表中删除## BeDel中的stackID。
#BeDel
StackID
45
56
48
56
49
DECLARE @flow int
@flow=(SELECT FLOWID FROM MainTable WHERE FLOWNAME='AAA')
MainTable
StackID VALUE FLOWID FLOWNAME
67 34 1 AAA
45 56 1 AAA
56 22 1 AAA
34 56 1 ZZZ
我已经使用了游标,但我不想因为性能原因而使用游标。
我的光标代码是
DECLARE Rotation CURSOR
FOR
SELECT StackID FROM #BeDel
DECLARE StackID INT
OPEN Rotation
FETCH NEXT FROM Rotation INTO @StackID
While @@FETCH_STATUS = 0
BEGIN
DELETE MainTable
WHERE StackID=@StackID AND FLOWID=@@flow
FETCH NEXT FROM Rotation INTO @StackID
END
答案 0 :(得分:1)
delete MainTable
from MainTable as m
where
exists (select * from #BeDel as b where b.StackID = m.StackID) and
m.FLOWNAME = 'AAA'