1

我必须使用@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
4

1 回答 1

1
delete MainTable
from MainTable as m
where
    exists (select * from #BeDel as b where b.StackID = m.StackID) and
    m.FLOWNAME = 'AAA'
于 2013-09-23T18:16:36.203 回答