What is cursor
what is a cursor why we use cursor
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
nallyaRank #8,588 · 219 reputationPosted Sep 17, 2012, 9:42 PM EDT
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 .
chandresh rathore40 reputationPosted Sep 17, 2012, 9:49 PM EDT
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