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 2005 Forums
 Transact-SQL (2005)
 what is the bettwer way to update the rows using

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2010-08-30 : 16:37:54
what is the better way to update the rows using select query:

select revid,dmid,DocumentID from TAB_ccsNetDMRevision where dmid=@dmid and DocumentID=@docid

---loop the following update statement with above select query resultset---

update #TEMPFINDOCR1 set revid=@revid, revno=@revno where type_id=@dmid and docid=@docid

Thank you very much for the helpful info.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-30 : 17:17:36
Join them together, do not loop.

Here's an example:

UPDATE t1
SET c1 = t2.c1, c2 = t2.c2
FROM Table1 t1
JOIN Table2 t2
ON t1.ID = t2.ID

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -