Monday, December 08, 2014

Simple Example of Cursor

This is the simplest example of the SQL Server Cursor. I have used this all the time for any use of Cursor in my T-SQL.
DECLARE @AccountID INT
DECLARE 
@getAccountID CURSOR
SET 
@getAccountID = CURSOR FOR
SELECT 
Account_IDFROM AccountsOPEN @getAccountIDFETCH NEXTFROM @getAccountID INTO @AccountIDWHILE @@FETCH_STATUS 0BEGIN
PRINT 
@AccountIDFETCH NEXTFROM @getAccountID INTO @AccountIDEND
CLOSE 
@getAccountIDDEALLOCATE @getAccountID

No comments:

Post a Comment