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  

Update Query Question



 
 
Thread Tools Display Modes
  #1  
Old May 26th, 2004, 08:06 PM
Edward
external usenet poster
 
Posts: n/a
Default Update Query Question

Hello. I have a table where I want to change the data in a specific field based on what that field contains using another table as a cross reference.

I could use a search and replace function: replace x with y but I have about 29 different values in that column I need to change to new values.

I have the cross reference table already but not sure of how to proceed or the sql syntax

update tablename, set fieldname = y, where fieldname = x..... or something like that.

Any assistance is appreciated....


  #2  
Old May 26th, 2004, 11:46 PM
BigManT
external usenet poster
 
Posts: n/a
Default Update Query Question


Ed,
You are breaking the laws of normalization which will only get your into trouble. You should only store any given piece of data in one place. Clearly you are storing the same data in more than one table. The efficient way to do this is to have a query pull the right data for display. Anyway, I'll answer your question. Create a query with a link between the two tables on a common field which is hoping the primary key in one of the tables. Switch the query to an update query. In the update row, put the name of the field which you want to update to.
Big Man T
  #3  
Old May 26th, 2004, 11:56 PM
eDWARD
external usenet poster
 
Posts: n/a
Default Update Query Question

Hi, thanks for the reply. I may not have clearly explained what I'm trying to do.

In the data table is a field where I want to change the data from one thing to another:

AA becomes 112
BB becomes 175
CC becomes 210

This is an illustration only, not actual data. the text represents a code and the numbers are simply a replacement for the code. There are multiple records with the same code, I could simply open the table, highlight the field and do a search and replace but as I have quite a number of replacements I am trying to do it through an update query..... It is a one time task.

Edward.
  #4  
Old May 27th, 2004, 11:43 AM
Gary Walter
external usenet poster
 
Posts: n/a
Default Update Query Question


"eDWARD" wrote

In the data table is a field where I want to change the data from one thing to

another:

AA becomes 112
BB becomes 175
CC becomes 210

This is an illustration only, not actual data. the text represents a code and the

numbers are simply a replacement for the code. There are multiple records with the
same code, I could simply open the table, highlight the field and do a search and
replace but as I have quite a number of replacements I am trying to do it through an
update query..... It is a one time task.

Hi Edward,

I think this is what you want:

UPDATE
tbl1 INNER JOIN tbl2
ON tbl1.PK = tbl2.PK
SET tbl1.f1 = tbl2.f1

In query designer

-add both tables
-join key(s) of both tables by drag and drop
a join field from original table to join field
of lookup table
-drag and drop field from original table you want
to update down to a field row
-change query from select to update
-in UpdateTo row, type in
tablename.fieldname from your lookup table.

test on copy of db to verify result

Good Luck,

Gary Walter


  #5  
Old May 27th, 2004, 09:26 PM
edward
external usenet poster
 
Posts: n/a
Default Update Query Question

thanks, i'll try that out.
 




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 02:23 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.