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 » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Using IF then statement in Update Query



 
 
Thread Tools Display Modes
  #1  
Old June 3rd, 2008, 04:32 PM posted to microsoft.public.access.tablesdbdesign
nstaton
external usenet poster
 
Posts: 1
Default Using IF then statement in Update Query

I have a table called Pole and a table called 2008PoleTreatmentPoles. I want
to update the table called Pole with the data in the table called
2008PoleTreatment Poles only if the date in the Pole table is the date in
the 2008PoleTreatmentPoles table. Can someone help me in how to set this up.
I already have the query set up to update the one table to the other; I just
don't know what to write for the date criteria. My query looks like this:

UPDATE Pole INNER JOIN 2008PoleTreatmentPoles ON Pole.UID =
[2008PoleTreatmentPoles].UID SET Pole.PoleNumber =
"2008PoleTreatmentPoles!POLENUMBER", Pole.Span_Backpole =
"2008PoleTreatmentPoles!SPAN_BACKPOLE", Pole.OsmosePole =
"2008PoleTreatmentPoles!OSMOSEPOLE", Pole.Inspection_Date =
"2008PoleTreatmentPoles!INSPECTION_DATE", Pole.BirthYear =
"2008PoleTreatmentPoles!BIRTHYEAR", Pole.Year_Treat =
"2008PoleTreatmentPoles!YEAR_TREAT", Pole.Down_Guy_Quantity =
"2008PoleTreatmentPoles!DOWN_GUY_QUANTIT", Pole.Anchor_Quantity =
"2008PoleTreatmentPoles!ANCHOR_QUANTITY", Pole.Height =
"2008PoleTreatmentPoles!HEIGHT", Pole.Class = "2008PoleTreatmentPoles!CLASS",
Pole.Telco = "2008PoleTreatmentPoles!TELCO", Pole.CATV =
"2008PoleTreatmentPoles!CATV", Pole.Fiber = "2008PoleTreatmentPoles!FIBER",
Pole.GPS_Date = "2008PoleTreatmentPoles!GPS_DATE", Pole.Datafile =
"2008PoleTreatmentPoles!DATAFILE";

Your help would be greatly appreciated
--
Nancy Staton
Central Virginia Electric Cooperative
  #2  
Old June 3rd, 2008, 06:32 PM posted to microsoft.public.access.tablesdbdesign
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Using IF then statement in Update Query

On Tue, 3 Jun 2008 08:32:02 -0700, nstaton
wrote:

I have a table called Pole and a table called 2008PoleTreatmentPoles. I want
to update the table called Pole with the data in the table called
2008PoleTreatment Poles only if the date in the Pole table is the date in
the 2008PoleTreatmentPoles table. Can someone help me in how to set this up.
I already have the query set up to update the one table to the other; I just
don't know what to write for the date criteria.


This query as written will update the fields to *THE NAMES OF* the fields in
the other table - not the contents of those fields!!! Not what you want at
all. You need to enclose fieldnames in [square brackets], not in "quote
marks".

Try

UPDATE Pole INNER JOIN 2008PoleTreatmentPoles
ON Pole.UID = [2008PoleTreatmentPoles].UID
SET Pole.PoleNumber = [2008PoleTreatmentPoles].[POLENUMBER],
Pole.Span_Backpole = [2008PoleTreatmentPoles].[SPAN_BACKPOLE],
Pole.OsmosePole = [2008PoleTreatmentPoles].[OSMOSEPOLE],
Pole.Inspection_Date = [2008PoleTreatmentPoles].[INSPECTION_DATE],
Pole.BirthYear = [2008PoleTreatmentPoles].[BIRTHYEAR],
Pole.Year_Treat = [2008PoleTreatmentPoles].[YEAR_TREAT],
Pole.Down_Guy_Quantity = [2008PoleTreatmentPoles].[DOWN_GUY_QUANTIT],
Pole.Anchor_Quantity = [2008PoleTreatmentPoles].[ANCHOR_QUANTITY],
Pole.Height = [2008PoleTreatmentPoles].[HEIGHT],
Pole.Class = [2008PoleTreatmentPoles].[CLASS],
Pole.Telco = [2008PoleTreatmentPoles].[TELCO],
Pole.CATV = [2008PoleTreatmentPoles].[CATV],
Pole.Fiber = [2008PoleTreatmentPoles].[FIBER],
Pole.GPS_Date = [2008PoleTreatmentPoles].[GPS_DATE],
Pole.Datafile = [2008PoleTreatmentPoles].[DATAFILE]
WHERE Pole.[datefield] [2008PoleTreatmentPoles].[datefield];

Substitute the name of the actual date field (which you did not post) for
"datefield" in the WHERE clause.

Back up your database before running this - update queries are a "one way
trapdoor" and if there's some other error in the query you won't be able to
back out, so be sure you TEST YOUR BACKUP before running the query.

--

John W. Vinson [MVP]
 




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


All times are GMT +1. The time now is 12:16 PM.


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