what is cursor
what is a cursor why we use cursor
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
chandresh rathorePosted Sep 18, 2012, 1:49 AM
DECLARE @ProductID INTDECLARE @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
nallyaPosted Sep 18, 2012, 1:42 AM
Cursors are a mechanism to explicitly enumerate through the rows of a result set, rather than retrieving it as such.
Cursor May Be used Like For loop , Where We have to retrieve or fetch number of Rows From The table For the particular Entity Then We Required A Cursor to Be Follow Simple Way . So I Prefer Where you Require For Loop Please Make Use of Cursor in Database
For Exanmple If I Require For Different Companies To Calculate Balance Sheet of Different Account Then I Will Apply Cursor For The Company Entity and Will retriev Data Of the Different account .