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)
 Update statement in cursor

Author  Topic 

BuddyRam
Starting Member

17 Posts

Posted - 2007-07-03 : 05:27:16
Hello,

I have to update a table while looping through it records based on condition..
my procedure is as foloows:
create procedure sample_update as
declare @id int
declare sel_publisher cursor for
select publisher_id from tblpublishers

open sel_publisher
fetch next from sel_publisher into @id
WHILE @@FETCH_STATUS = 0
BEGIN
--if @id > 30 then
--My update statementlike
-- update tblpublishers set newid = 31 where where id = @id
--end if
FETCH NEXT FROM Employee_Cursor into @id

END
close sel_publisher
deallocate
end sample_update

I have to put my update statement based on if condition , howcan i do it???

Thanks

Cheers
Ram

Ifor
Aged Yak Warrior

700 Posts

Posted - 2007-07-03 : 05:38:18
Ditch the cursor.
UPDATE tblpublishers
SET [newid] = 31
WHERE publisher_id > 30

Go to Top of Page
   

- Advertisement -