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)
 help with cursors

Author  Topic 

hmusa
Starting Member

36 Posts

Posted - 2001-03-29 : 08:36:04
I have the following update statement that i am using to update a table from another:

update testing1
set student_id = (select student_id from testing2 where stagecode ='p01')
where check ='1 '


works fine

but i have over 300 records that i need to update, i thought a cursors could be used, so i used the following code, i've never used cursors and the folowing code will show




declare @student_id char (11)


declare mycursor scroll cursor
for select student_id from testing2 where stagecode = 'p01 '

open mycursor

fetch first from mycursor
into @student_id

while @@fetch_status = 0
begin
update testing1
set student_id = @student_id
where [check]= '2 '

fetch next from mycursor


end
close mycursor
deallocate mycursor

it obviously does not work, can anyone help.

thanxs



   

- Advertisement -