有没有人知道如何为同一个游标设置不同的选择语句?我需要这样的想法。
DECLARE Temp_Cursor CURSOR FOR
IF(@TempVar = 1)
BEGIN
SELECT CustomerId FROM Customers
END
ELSE IF(@TempVar = 2)
BEGIN
SELECT OrderId FROM Orders
END
OPEN Temp_Cursor;
FETCH NEXT FROM TempCursor INTO @TempObjectId
WHILE @@FETCH_STATUS = 0
BEGIN
.... ETC
我找到了解决方案:DECLARE @Temp_Cursor CURSOR
IF(@TempVar = 1)
BEGIN
SET @Temp_Cursor = CURSOR FOR
SELECT CustomerId FROM Customers
END
ELSE IF(@TempVar = 2)
BEGIN
SET @Temp_Cursor = CURSOR FOR
SELECT OrderId FROM Orders
END
OPEN @Temp_Cursor;
FETCH NEXT FROM @TempCursor INTO @TempObjectId
WHILE @@FETCH_STATUS = 0
BEGIN