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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 how to count of rows in a dynamic cursor

Author  Topic 

DURGESH
Posting Yak Master

105 Posts

Posted - 2008-06-27 : 02:18:45
declare @emp varchar(50),@ctr int
declare cur_test cursor for select emp from employees
open cur_test
fetch next from cur_test into @emp
while @@fetch_status=0
begin
select @ctr=?
fetch next from cur_test into @emp
end
close cur_test
deallocate cur_test

i wanna to know total records of cur_test

thanks in advance

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-27 : 02:21:30
put a counter variable with intial value 1 and increment it inside while loop. at the end of loop, you'll get count of records parsed by cusrsor.
Go to Top of Page

DURGESH
Posting Yak Master

105 Posts

Posted - 2008-06-27 : 02:37:41
quote:
Originally posted by visakh16

put a counter variable with intial value 1 and increment it inside while loop. at the end of loop, you'll get count of records parsed by cusrsor.


that i can get by using count in the select query
i want to know is there any built-in procedure or function to get the count of dynamic cursor
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-27 : 04:27:42
Yes. I think it's called @@CURSOR_ROWS.


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-06-27 : 09:43:42
quote:
Originally posted by DURGESH

declare @emp varchar(50),@ctr int
declare cur_test cursor for select emp from employees
open cur_test
fetch next from cur_test into @emp
while @@fetch_status=0
begin
select @ctr=
fetch next from cur_test into @emp
end
close cur_test
deallocate cur_test

i wanna to know total records of cur_test

thanks in advance


What are you doing with this code?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-02 : 08:55:15
quote:
Originally posted by DURGESH

declare @emp varchar(50),@ctr int
declare cur_test cursor for select emp from employees
open cur_test
fetch next from cur_test into @emp
while @@fetch_status=0
begin
select @ctr=?
fetch next from cur_test into @emp
end
close cur_test
deallocate cur_test

i wanna to know total records of cur_test

thanks in advance


Dont edit the Question
Post it as new reply

Can count(*) do what you need?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-02 : 15:35:52
Read about @@CURSOR_ROWS in Books Online.




E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

DURGESH
Posting Yak Master

105 Posts

Posted - 2008-07-03 : 05:51:54
yes
i wanna know how records were selected by cursor
cur_test



thanks in advance
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-07-03 : 05:59:46
quote:
Originally posted by DURGESH

yes
i wanna know how records were selected by cursor
cur_test



thanks in advance



Not sure what do you mean by that. Could you elaborate?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -