2008年12月5日 星期五

SQL Server CURSOR

-- DEMO CURSOR
DECLARE @ContactName nvarchar(30)
DECLARE CUR CURSOR FOR
SELECT ContactName FROM Northwind.dbo.Customers

OPEN CUR
FETCH CUR INTO @ContactName

WHILE (@@FETCH_STATUS=0)
BEGIN

PRINT @ContactName

FETCH CUR INTO @ContactName
END

CLOSE CUR
DEALLOCATE CUR

GO

沒有留言: