Solved

Cursor processing record count.

Posted on 2010-11-08
3
519 Views
Last Modified: 2012-05-10
HI, I am running a cursor which is updating around 15000
records in a table.

I need to see the number of records which are getting updated
or processed by the cursor while the query is running..

Can anyone please let me know how do i do that in a easy
manner without affecting the performance of my Cursor ?

Thanks
0
Comment
Question by:gvamsimba
  • 3
3 Comments
 
LVL 58

Assisted Solution

by:cyberkiwi
cyberkiwi earned 500 total points
ID: 34086839
> while the query is running..

You mean like a progressbar counter?  Not possible... unless you want to see the messages keep scrolling like

processing #1
processing #2
processing #3
processing #4
processing #5
etc

which will flood the messages window
0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 34086849
If you mean a count after the loop is complete, then something like a counter

declare @counter int
set @counter = 0
while @@FETCH_STATUS = 0 begin
      set @counter = @counter + 1
      .....
      fetch next from mycursor .....
end
print convert(varchar(10), @counter) + ' records processed in cursor'
0
 
LVL 58

Assisted Solution

by:cyberkiwi
cyberkiwi earned 500 total points
ID: 34086874
Re the first case, you can use

declare @counter int, @msg varchar(200)
set @counter = 0
while @@FETCH_STATUS = 0 begin
      set @counter = @counter + 1
      set @msg = 'processing #' + convert(varchar(10), @counter)
      RAISERROR(@msg,0,1) WITH NOWAIT;
      .....
      fetch next from mycursor .....
end
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now