Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Count of record from cursor.

Author  Topic 

hspatil31
Posting Yak Master

182 Posts

Posted - 2011-05-27 : 07:07:38
Hi All,

How to take the count of record from cusrsor ?

Thanks and Regard's
Harish Patil

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-05-27 : 07:24:54
Not sure what you mean.

Select count(*) from yourTable?

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2011-05-27 : 07:58:38
are you counting based on a particular criteria?
Go to Top of Page

jcelko
Esteemed SQL Purist

547 Posts

Posted - 2011-05-29 : 18:59:29
Why are you writing a cursor at all? Why not use a COUNT(*)? That will give you the number of rows in a table which is not quite the same as a count of records in a cursor.

--CELKO--
Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2011-05-30 : 02:56:42
You should generally stay away from cursors, they are the devil.

Now regardng your question: SELECT @@CURSOR_ROWS

From BOL:
@@CURSOR_ROWS
Reports the number of rows populated in the last cursor opened for the connection.


- Lumbago
My blog-> http://thefirstsql.com/2011/02/07/regular-expressions-advanced-string-matching-and-new-split-function-sql-server-2008-r2/
Go to Top of Page

hspatil31
Posting Yak Master

182 Posts

Posted - 2011-05-30 : 04:32:47
Hello Friend,

I have tried "@@CURSOR_ROWS" but it returns -1 if rows available in cusrsor.
I am having following cursor, in that i want all field from select staement and i want count of record also coz i want to check if records are more than 1.

Can you please help me how to do this ?


DECLARE find_lcc_cursor CURSOR LOCAL FORWARD_ONLY READ_ONLY FOR
SELECT INRS.ID AS Normalized_Rate_Sheet_ID, WS.ID as Work_Sheet_ID,Call_Completion, INRS.Rate FROM tb_lcr_international_normalized_rate_sheet INRS
INNER JOIN tb_lcr_work_sheet WS ON INRS.Work_Sheet_ID=WS.ID
INNER JOIN tb_lcr_rate_sheet RS ON RS.ID=WS.Rate_Sheet_ID
INNER JOIN tb_lcr_carrier C ON C.ID=RS.Carrier_ID
INNER JOIN tb_lcr_country Coun on COUN.ID=INRS.Country_ID
WHERE COUN.Code=@Country_Code AND Dialed_Digits=@Dialed_Digits AND INRS.Status=1 AND RS.ID IN (SELECT Rate_Sheet_ID FROM tb_lcr_rate_deck_detail RD INNER JOIN tb_lcr_rate_deck_carrier_rate_sheet RDRSH on RDRSH.Rate_Deck_Details_ID=RD.ID WHERE RD.ID=@Rate_Deck_Detail_ID)
ORDER BY INRS.Rate,C.priority,INRS.Work_Sheet_ID


Thnks,
Harish
Go to Top of Page
   

- Advertisement -