Sunday, 23 February 2014

Could you please explain, how to use Cursors ?

  1. Declare a CURSOR
  2. OPEN a CURSOR
  3. FETCH data in CURSOR
  4. finally close CURSOR
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

Note: only a member of this blog may post a comment.