我想知道你是否可以在fetch结束后从fetch语句中定义的变量中进行选择。例如下面,@ str2 = @ Column1?还是@ str2等于什么?
USE AdventureWorks2008R2;
GO
DECLARE contact_cursor CURSOR FOR
SELECT LastName FROM Person.Person
WHERE LastName LIKE 'B%'
ORDER BY LastName;
OPEN contact_cursor;
-- Perform the first fetch.
FETCH NEXT FROM contact_cursor;
Into @Column1
-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM contact_cursor;
END
Select @str2 = @Column1
EXEC (@str2)
CLOSE contact_cursor;
DEALLOCATE contact_cursor;
GO