2

以下是否可能:

EXEC sp_Edu3_DeleteTreeStructure(从 TreeStructures 中选择 TreeStructureId)

SP 通常采用一个参数。我想要的是为查询找到的每个 TreeStructureId 执行 SP。

谢谢,列文卡登

4

1 回答 1

2

您可以使用 CURSOR 来执行此操作。

DECLARE @treeStructureId int

DECLARE TreeStructureCursor CURSOR FOR
    SELECT
        TreeStructureId
    FROM
        TreeStructures

OPEN TreeStructureCursor

FETCH NEXT FROM TreeStructureCursor
INTO @treeStructureId

WHILE @@FETCH_STATUS = 0
BEGIN
    EXEC sp_Edu3_DeleteTreeStructure(@treeStructureId)

    FETCH NEXT FROM TreeStructureCursor
    INTO @treeStructureId
END

CLOSE TreeStructureCursor
DEALLOCATE TreeStructureCursor
于 2009-03-17T13:40:37.143 回答