Quantcast
Channel: Cursor Question
Viewing all articles
Browse latest Browse all 9

Cursor Question

$
0
0

Why did you comment out the first Fetch Next?  If you uncomment it, then it will work.  The problem you are having with the code as it is is that a the end of the first run @@FETCH_STATUS is not zero, (that's why you drop out of the loop).  But the only thing that changes @@FETCH_STATUS for your connection is doing another fetch.  So, with the code as you have it, running it the second time, you get to the WHILE statement, @@FETCH_STATUS is still not  zero, so you never even enter the loop.

But a much more important question is why are you trying to learn about cursors?  If you are new to SQL Server, you should know that while there are a few cases where cursors are the only or the best way to do things, in virtually all cases you want a set based solution.  Cursors in SQL are generally major performance problems.  They work fine when you have only a few rows, but have terrible performance when you get a "real world" database size. 

Tom


Viewing all articles
Browse latest Browse all 9

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>