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
 General SQL Server Forums
 New to SQL Server Programming
 sql loop query

Author  Topic 

craigmacca
Posting Yak Master

142 Posts

Posted - 2009-03-11 : 12:44:42
Hi i have a table "copyTable" with 2 columns "id" and "add_1"

i need to update another table "testTable" and update

1. loop through "copyTable"
2. update "testTable"
3. set "testTable.add_1" = "copyTable.add_1"
4. where "testTable.Id" = "copyTable.Id"

just not sure how to do this in a stored proc?

guptam
Posting Yak Master

161 Posts

Posted - 2009-03-11 : 12:50:15
UPDATE testTable
SET testTable.add_1 = copyTable.add_1
FROM copyTable
WHERE testTable.ID = copyTable.ID

Thanks.

--
Mohit K. Gupta
B.Sc. CS, Minor Japanese
MCITP: Database Administrator
MCTS: SQL Server 2005
http://sqllearnings.blogspot.com/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-11 : 13:16:49
use inner join

UPDATE tt
SET tt.add_1 = ct.add_1
FROM testTable tt
INNER JOIN copyTable ct
ON tt.ID = ct.ID
Go to Top of Page
   

- Advertisement -