Hey there..
Basically, as the subject says, my cursors in my stored procedures return the last row of its resultset twice. I was wondering why this is happening. Heres a basic structure of my cursors. Am i doing anything wrong here?
create proc check_no_letter_type as
begin
declare @ltr_type varchar(5)
declare rr_t cursor for
select distinct letter_type from letter_log_rr
open rr_t
create table #ltr_type ( letter_type varchar (5), no_of_letters int)
while (@@sqlstatus !=2)
begin
fetch rr_t into @ltr_type
insert #ltr_type
select
@ltr_type, count(*) from letter_log_rr
where
letter_type = @ltr_type
end
close rr_t
deallocate cursor rr_t
select #ltr_type.letter_type, #ltr_type.no_of_letters from #ltr_type
drop table #ltr_type
end
what it gives is
letter_type no_of_letters
-------------------------------------------
A 10
B 15
C 12
D 22
D 22
As you can see the last row is repeated..
Anybody can help me here?
TIA
JD
Basically, as the subject says, my cursors in my stored procedures return the last row of its resultset twice. I was wondering why this is happening. Heres a basic structure of my cursors. Am i doing anything wrong here?
create proc check_no_letter_type as
begin
declare @ltr_type varchar(5)
declare rr_t cursor for
select distinct letter_type from letter_log_rr
open rr_t
create table #ltr_type ( letter_type varchar (5), no_of_letters int)
while (@@sqlstatus !=2)
begin
fetch rr_t into @ltr_type
insert #ltr_type
select
@ltr_type, count(*) from letter_log_rr
where
letter_type = @ltr_type
end
close rr_t
deallocate cursor rr_t
select #ltr_type.letter_type, #ltr_type.no_of_letters from #ltr_type
drop table #ltr_type
end
what it gives is
letter_type no_of_letters
-------------------------------------------
A 10
B 15
C 12
D 22
D 22
As you can see the last row is repeated..
Anybody can help me here?
TIA
JD