Tuesday, September 18, 2012

Cursor

« SQL SERVER – 2005 – A Simple Way To Defragment All Indexes In A Database That Is Fragmented Above A Declared ThresholdSQLAuthority News – SQL Server 2005 is The Data Platform Leader »
SQL SERVER – Simple Example of Cursor – Sample Cursor Part 2
March 5, 2008 by pinaldave
I have recently received email that I should update SQL SERVER – Simple Example of Cursor with example of AdventureWorks database.

Simple Example of Cursor using AdventureWorks Database is listed here.

USE AdventureWorks
GO
DECLARE @ProductID INT
DECLARE @getProductID CURSOR
SET @getProductID = CURSOR FOR
SELECT ProductID
FROM Production.Product
OPEN @getProductID
FETCH NEXT
FROM @getProductID INTO @ProductID
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @ProductID
FETCH NEXT
FROM @getProductID INTO @ProductID
END
CLOSE @getProductID
DEALLOCATE @getProductID
GO


Reference : Pinal Dave (http://blog.SQLAuthority.com)

No comments:

Post a Comment