Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cursor question

Status
Not open for further replies.

wbodger

Programmer
Apr 23, 2007
769
US
I have a job that runs very frequently that uses a cursor. Is there an easy way to see how many records are in that cursor? I would like to have it mail me the number of rows in the cursor every time it runs for a little while so I can get an idea how much work it is really doing.

Thanks,
Willie
 
You will need to issue the select statement again with a count instead of opening it in the cursor to get the number of records in the cursor.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
or you could just include a counter variable in the cursor and after the loop, just return that counter...

--------------------
Procrastinate Now!
 
just remembered, you could also use the @@rowcount property straight after the select statement in the opening of the cursor...

--------------------
Procrastinate Now!
 
OK, I was thinking about the counter, just wasn't sure if Cursors had some special property. Thanks!

WB
 
I tested using @@ROWCOUNT just after opening the cursor and got 0 records in @@ROWCOUNT when there were 5 records in the cursor.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top