Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add column of data to table

Status
Not open for further replies.

iroosma

Technical User
Jun 25, 2004
11
0
0
US
I have a table that I need to add a column to. I have the column in another table. I basically need to copy it from the original table and put it on the end of the other table. When I do a SELECT INTO the data gets put at the bottom of the new column, I need the data to be at the top of the column. Does anyone have any ideas of how I can do this

Thanks
 
What are tops and bottoms of columns? I can only assume that you want to add a field to a table and then update the values in this field with values from a related record in another table.

This is an Update query and requires a relationship between unique values in at least one of the tables.

If this explanation doesn't help then you should provide some sample records from your tables and the desired results.

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
you need to perform an update. like:

Code:
update tbl1, tbl2 set tbl1.thenewfield = tbl2.thefield;

if the values in the new field are depending on a key, you need to have this key in both tables and join them:

Code:
update tbl1 inner join tbl2 on tbl1.key = tbl2.key set tbl1.thenewfield = tbl2.thefield;

HTH,
fly

Martin Serra Jr.
 
To do this you first need to alter the table by adding a new field. Then you need to run an action to update the data from table1 to the new table's new field.

Code:
Dim db As Database
Set db = CurrentDB
db.Execute "ALTER TABLE [i][red]yourtablename1[/red][/i] " & _
& "ADD COLUMN [i][blue]newfieldname[/blue][/i] TEXT (25);"
db.close
DoCmd.OpenQuery "qryUpdateNewField"

SQL code for qryUpdateNewField:
Code:
Update [i][red]yourtablename1[/red][/i] as A INNER JOIN [i][red]yourtablename2[/red][/i] as B ON A.[I]linkfield[/i] = A.[I]linkfield[/i] SET A.[I]NEWfield[/i] = B.[I]NEWfield[/i];

I think this should work for you. Let me know if you have any questions.


[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top