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)
 store proc. - code posted - doesn't loop

Author  Topic 

abarsami
Yak Posting Veteran

68 Posts

Posted - 2001-06-21 : 15:45:26
I tried it with a cursor first and it took way too long.
Now I did it this way and the problem is it doesn't go to the next record. How can I get it to loop, without using a cursor.
Thanks

declare @mc_code varchar(20)
declare @mg_code varchar(20)
declare @date datetime
declare @zcode varchar(20)
declare @counter int
declare @max int
set nocount on


select @counter=0

select @mc_code=d.mc_code,
@mg_code=ms.mg_code,
@z_code=c.z_code,
@date=c.date
from TableC c join tableD d on(c.category_no=d.category_no)
join MC mc on(d.mc_code=mc.mc_code)
join MS ms on(mc.ms_code=ms.ms_code)

select @max = @@rowcount


While @counter < @max
Begin

Update TableC
set mc_code = @mc_code
where date= @date
and z_code = @z_code

Update TableC
set mg_code = @mg_code
where date = @date
and z_code = @z_code

select @counter = @counter + 1
End



   

- Advertisement -