A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Help with Update statement



 
 
Thread Tools Display Modes
  #1  
Old September 6th, 2005, 02:11 PM
Net
external usenet poster
 
Posts: n/a
Default Help with Update statement

Here is an Update statement:

UPDATE Sample, Main
SET Main.State = Sample.State, Main.ST = Sample.ST
WHERE Main.BU=Sample.BU And Main.Desc=Sample.Desc ;

How come the update is not working correctly?
For some reason it updates with the values from the first row and not on the
Where clause?

Thanks in advance,

  #2  
Old September 6th, 2005, 08:12 PM
George Nicholson
external usenet poster
 
Posts: n/a
Default

1) You need to JOIN your tables. I think you have JOIN and WHERE confused.
WHERE acts as a Filter, and I don't see that a filter is required. JOIN
(which you do need and is missing entirely from your SQL) describes the
"connection" between the tables.

2) I don't see that you are updating anything in Sample, just using it as a
datasource, so it shouldn't be in the UPDATE clause, but you do need to JOIN
it.

My guess is you want something more like:

UPDATE Main
INNER JOIN Sample ON (Main.BU = Sample.BU) AND (Main.Desc = Sample.Desc)
SET Main.State = Sample.State, Main.ST = Sample.ST

That should update the State and ST fields in Main with the corresponding
values from Sample for all records having matching BU and Desc entries in
both tables.

HTH,
--
George Nicholson

Remove 'Junk' from return address.


"Net" wrote in message
...
Here is an Update statement:

UPDATE Sample, Main
SET Main.State = Sample.State, Main.ST = Sample.ST
WHERE Main.BU=Sample.BU And Main.Desc=Sample.Desc ;

How come the update is not working correctly?
For some reason it updates with the values from the first row and not on
the
Where clause?

Thanks in advance,



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
if statement in UPDATE Tom Running & Setting Up Queries 1 June 30th, 2005 08:23 PM
Help with update query and IIf statement Raj Running & Setting Up Queries 3 April 19th, 2005 07:25 PM
Office XP Update Problem Bill General Discussions 0 December 1st, 2004 06:11 PM
Using Hyperlinks in Mail Merge IF...THEN...ELSE Statements Mark V Mailmerge 8 November 30th, 2004 01:31 PM
Syntax for the UPDATE statement JTJams General Discussion 13 September 15th, 2004 04:17 PM


All times are GMT +1. The time now is 04:41 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.