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)
 T-SQL Update Loop

Author  Topic 

Gyto
Posting Yak Master

144 Posts

Posted - 2007-02-01 : 11:59:50
Hi there,

I have written the following test SQL statement in query analyser:

UPDATE PremAddTest1 SET PremAddTest1.DatabaseRef = PremAddTest2.DatabaseRef FROM PremAddTest2
WHERE PremAddTest1.Parish = PremAddTest2.Parish AND PremAddTest1.Site = PremAddTest2.Site AND PremAddTest1.Parish = PremAddTest2.Premise;


All I need to do is perform this statement on every row in the PremAddTest1 table, but I'm not sure of the syntax for this.

Something like:


FOR each row in PremAddTest1

run update statement

Move to next row


Can anyone help?

Thanks

nr
SQLTeam MVY

12543 Posts

Posted - 2007-02-01 : 12:43:45
That statement will update every row in the table.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Gyto
Posting Yak Master

144 Posts

Posted - 2007-02-02 : 04:36:26
quote:
Originally posted by nr

That statement will update every row in the table.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.


Hmmm.....I ran it in query analyser and it only updated the first row.....weird.....
Go to Top of Page

Gyto
Posting Yak Master

144 Posts

Posted - 2007-02-02 : 04:43:07
Ooops.....it was a typo.....should've been:

PremAddTest1.PREMISE = PremAddTest2.Premise


lol.....I thought it was a bit strange......d'oh
Go to Top of Page
   

- Advertisement -