emccormick
MIS
SQL2005, W2K3-SP2
I can't see why the cursor in this stored procedure won't move past the 1st row. The select statement hits a table with ~5k unique AuthorizationNumber(s).
The while loop works because the @Count increments, but the other vars just sit on the first row.
------
ALTER procedure [glopp].[meetcomp_parse]
as begin
declare @AuthorizationNumber varchar(100);
declare @Competitor1 varchar(100);
declare @CompmodelNumber1 varchar(100);
declare @CompEUPrice1 varchar(100);
declare @CompPPrice1 varchar(100);
declare @CompDstPrice_1 varchar(100);
declare @CompResPrice1 varchar(100);
declare @Competitor2 varchar(100);
declare @CompmodelNumber2 varchar(100);
declare @CompEUPrice2 varchar(100);
declare @CompPPrice2 varchar(100);
declare @CompDstPrice_2 varchar(100);
declare @CompResPrice2 varchar(100);
declare @Competitor3 varchar(100);
declare @CompmodelNumber3 varchar(100);
declare @CompEUPrice3 varchar(100);
declare @CompPPrice3 varchar(100);
declare @CompDstPrice_3 varchar(100);
declare @CompResPrice3 varchar(100);
declare @Competitor4 varchar(100);
declare @CompmodelNumber4 varchar(100);
declare @CompEUPrice4 varchar(100);
declare @CompPPrice4 varchar(100);
declare @CompDstPrice_4 varchar(100);
declare @CompResPrice4 varchar(100);
declare @Competitor5 varchar(100);
declare @CompmodelNumber5 varchar(100);
declare @CompEUPrice5 varchar(100);
declare @CompPPrice5 varchar(100);
declare @CompDstPrice_5 varchar(100);
declare @CompResPrice5 varchar(100);
declare @count int;
set @count = 0;
declare mycursor cursor for
select
distinct(AuthorizationNumber),
Competitor1,
CompmodelNumber1,
CompEUPrice1,
CompPPrice1,
CompDstPrice_1,
CompResPrice1,
Competitor2,
CompmodelNumber2,
CompEUPrice2,
CompPPrice2,
CompDstPrice_2,
CompResPrice2,
Competitor3,
CompmodelNumber3,
CompEUPrice3,
CompPPrice3,
CompDstPrice_3,
CompResPrice3,
Competitor4,
CompmodelNumber4,
CompEUPrice4,
CompPPrice4,
CompDstPrice_4,
CompResPrice4,
Competitor5,
CompmodelNumber5,
CompEUPrice5,
CompPPrice5,
CompDstPrice_5,
CompResPrice5
from meetcomp;
open mycursor
fetch next from mycursor into
@AuthorizationNumber,
@Competitor1,
@CompmodelNumber1,
@CompEUPrice1,
@CompPPrice1,
@CompDstPrice_1,
@CompResPrice1,
@Competitor2,
@CompmodelNumber2,
@CompEUPrice2,
@CompPPrice2,
@CompDstPrice_2,
@CompResPrice2,
@Competitor3,
@CompmodelNumber3,
@CompEUPrice3,
@CompPPrice3,
@CompDstPrice_3,
@CompResPrice3,
@Competitor4,
@CompmodelNumber4,
@CompEUPrice4,
@CompPPrice4,
@CompDstPrice_4,
@CompResPrice4,
@Competitor5,
@CompmodelNumber5,
@CompEUPrice5,
@CompPPrice5,
@CompDstPrice_5,
@CompResPrice5
while @@fetch_status = 0
begin
print @@fetch_status;
print @count;
print @AuthorizationNumber;
print @Competitor1;
print @Competitor2;
print @Competitor3;
print @Competitor4;
print @Competitor5;
set @count = @count + 1;
end;
close mycursor;
deallocate mycursor;
end;
--------
Yes, the table structure leaves plenty to be desired and most would say making cursors this big is bad as well.
Can anyone see any syntax problems?
Is there a limit to the number of vars a cursor can hold?
Thanks!
e
I can't see why the cursor in this stored procedure won't move past the 1st row. The select statement hits a table with ~5k unique AuthorizationNumber(s).
The while loop works because the @Count increments, but the other vars just sit on the first row.
------
ALTER procedure [glopp].[meetcomp_parse]
as begin
declare @AuthorizationNumber varchar(100);
declare @Competitor1 varchar(100);
declare @CompmodelNumber1 varchar(100);
declare @CompEUPrice1 varchar(100);
declare @CompPPrice1 varchar(100);
declare @CompDstPrice_1 varchar(100);
declare @CompResPrice1 varchar(100);
declare @Competitor2 varchar(100);
declare @CompmodelNumber2 varchar(100);
declare @CompEUPrice2 varchar(100);
declare @CompPPrice2 varchar(100);
declare @CompDstPrice_2 varchar(100);
declare @CompResPrice2 varchar(100);
declare @Competitor3 varchar(100);
declare @CompmodelNumber3 varchar(100);
declare @CompEUPrice3 varchar(100);
declare @CompPPrice3 varchar(100);
declare @CompDstPrice_3 varchar(100);
declare @CompResPrice3 varchar(100);
declare @Competitor4 varchar(100);
declare @CompmodelNumber4 varchar(100);
declare @CompEUPrice4 varchar(100);
declare @CompPPrice4 varchar(100);
declare @CompDstPrice_4 varchar(100);
declare @CompResPrice4 varchar(100);
declare @Competitor5 varchar(100);
declare @CompmodelNumber5 varchar(100);
declare @CompEUPrice5 varchar(100);
declare @CompPPrice5 varchar(100);
declare @CompDstPrice_5 varchar(100);
declare @CompResPrice5 varchar(100);
declare @count int;
set @count = 0;
declare mycursor cursor for
select
distinct(AuthorizationNumber),
Competitor1,
CompmodelNumber1,
CompEUPrice1,
CompPPrice1,
CompDstPrice_1,
CompResPrice1,
Competitor2,
CompmodelNumber2,
CompEUPrice2,
CompPPrice2,
CompDstPrice_2,
CompResPrice2,
Competitor3,
CompmodelNumber3,
CompEUPrice3,
CompPPrice3,
CompDstPrice_3,
CompResPrice3,
Competitor4,
CompmodelNumber4,
CompEUPrice4,
CompPPrice4,
CompDstPrice_4,
CompResPrice4,
Competitor5,
CompmodelNumber5,
CompEUPrice5,
CompPPrice5,
CompDstPrice_5,
CompResPrice5
from meetcomp;
open mycursor
fetch next from mycursor into
@AuthorizationNumber,
@Competitor1,
@CompmodelNumber1,
@CompEUPrice1,
@CompPPrice1,
@CompDstPrice_1,
@CompResPrice1,
@Competitor2,
@CompmodelNumber2,
@CompEUPrice2,
@CompPPrice2,
@CompDstPrice_2,
@CompResPrice2,
@Competitor3,
@CompmodelNumber3,
@CompEUPrice3,
@CompPPrice3,
@CompDstPrice_3,
@CompResPrice3,
@Competitor4,
@CompmodelNumber4,
@CompEUPrice4,
@CompPPrice4,
@CompDstPrice_4,
@CompResPrice4,
@Competitor5,
@CompmodelNumber5,
@CompEUPrice5,
@CompPPrice5,
@CompDstPrice_5,
@CompResPrice5
while @@fetch_status = 0
begin
print @@fetch_status;
print @count;
print @AuthorizationNumber;
print @Competitor1;
print @Competitor2;
print @Competitor3;
print @Competitor4;
print @Competitor5;
set @count = @count + 1;
end;
close mycursor;
deallocate mycursor;
end;
--------
Yes, the table structure leaves plenty to be desired and most would say making cursors this big is bad as well.
Can anyone see any syntax problems?
Is there a limit to the number of vars a cursor can hold?
Thanks!
e