Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 1st, 2007, 01:06 PM
Registered User
 
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default T-SQL Update Loop

Hi there,

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

Code:
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:

Code:
FOR each row in PremAddTest1

run update statement

Move to next row
Can anyone help?

Thanks

 
Old February 1st, 2007, 01:27 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Updates are cascading meaning:

Update table set column = value

will update every row in your database. Your where statement will determine which rows are updated.

================================================== =========
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
 
Old February 2nd, 2007, 05:38 AM
Registered User
 
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by dparsons
 Updates are cascading meaning:

Update table set column = value

will update every row in your database. Your where statement will determine which rows are updated.

================================================== =========
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
I thought that was the case, but it only seemed to update the first row.....strange.....I will go back and fiddle with it :P ...thanks!

 
Old February 2nd, 2007, 05:52 AM
Registered User
 
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ooops.....it was a typo.....should've been:


PremAddTest1.PREMISE = PremAddTest2.Premise


lol.....I thought it was a bit strange......d'oh






Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP dynamic SQL query with for loop? hman Classic ASP Databases 3 December 13th, 2006 08:56 PM
loop through listbox and update record stoneman Access 1 August 5th, 2005 03:43 AM
Do Loop and SQL Freddyfred Access VBA 0 November 28th, 2004 06:47 PM
For loop in SQL SERVER 2000 Asish SQL Server 2000 2 May 13th, 2004 04:25 AM
update records by the loop mateenmohd SQL Server 2000 2 July 16th, 2003 06:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.