-------------------------------------- Halloween problem script -------------------------------------- drop table halloweenProblem create table halloweenProblem (pk int not null primary key, Name varchar(20), salary money) insert into halloweenProblem(pk, Name, Salary) values(1,'Joe Blow',20000.00) insert into halloweenProblem(pk, Name, Salary) values(2,'Joe Smith',30000.00) insert into halloweenProblem(pk, Name, Salary) values(3,'Jane Doe',40000.00) insert into halloweenProblem(pk, Name, Salary) values(4,'Boss Man',50000.00) declare RaiseSalary cursor for select salary, pk from halloweenProblem where salary < 50000 order by pk FOR UPDATE OF pk open RaiseSalary fetch RaiseSalary while @@fetch_status =0 begin update halloweenProblem set pk=pk*10 WHERE CURRENT OF RaiseSalary select * from halloweenProblem fetch RaiseSalary end close RaiseSalary deallocate RaiseSalary DECLARE abc CURSOR FOR SELECT salary FROM halloweenProblem where salary < 50000 order by salary for update of salary OPEN abc GO FETCH NEXT FROM abc GO UPDATE halloweenProblem SET salary= salary*2 WHERE CURRENT OF abc GO close abc deallocate abc --------------------------------------