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
 Transact-SQL (2000)
 Using Cursor How to Update The Record

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-01 : 15:11:39
satyam writes "I am trying to update the Record in a table.
suppose in my table there is 1000 records. I want to Update the record for some condition. If it is matched then it should by update by another and so on and so forth. Right now i am using Four update command to update the record. For that mine have to move all the 4 * 1000 record. So i want to use cursor to update the record. I hope by this way i have to move only by 1000 record. Pls solve my Problem. I am waiting for your reply.

Regards:
Satyam kumar"

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2005-08-01 : 15:11:39
Can you post your SQL statement? Doing 4 updates will probably be faster than doing 1,000 indidivual updates -- even if each of those updates touches all 1,000 records.
Go to Top of Page

nitin1353
Constraint Violating Yak Guru

381 Posts

Posted - 2005-08-01 : 16:00:58

DECLARE c2 CURSOR FOR SELECT password FROM tbl1 where <condition> FOR UPDATE OF password
OPEN c2
FETCH NEXT FROM c2

WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE tbl1 SET password = left(cast(rand()*10000000000000000 as numeric),9) WHERE CURRENT OF c2
FETCH NEXT FROM c2
END

CLOSE c2
DEALLOCATE c2

Regards
Nitin
Go to Top of Page
   

- Advertisement -