Need to move data from one table into another, using query

NateofMT

New Member
Joined
Jul 11, 2002
Messages
13
I need to copy a row, or multiple rows, from one table into another table and then delete it out of the first table, all based on the reults of a query.

Here is my sql statement for that query (named HasItBeenShippedQuery):

SELECT Job_Table.Ticket_Number, Job_Table.Ship_Sig
FROM Job_Table
WHERE (((Job_Table.Ship_Sig)<>""));

The name of the original table is Jobs_Table, the new table is Completed_Jobs_Table. The Completed_Jobs_Table will be appended to.

Will someone help me with the code to copy and delete? I am using a command button to run it and there will be no other user intervention.

Thanks,
Nateofmt
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Re: Need to move data from one table into another, using que

Hi NateofMT

For this to happen you need to separate the work into two operations.

Firstly, an INSERT INTO statement to add the records from table 1 into table2, like so:

Code:
INSERT INTO Completed_Jobs_Table
SELECT Job_Table.Ticket_Number, Job_Table.Ship_Sig 
FROM Job_Table 
WHERE (((Job_Table.Ship_Sig)<>""));

Of course here, the two tables will have the exact same structure(Number of fields, data types) or else you will need to add a VALUES ststement into the mix.

Next, we delete the rows from table1 like so:

Code:
DELETE (Job_Table.*) <-- Optional Extra if the records are all in one table
FROM Job_Table
WHERE (((Job_Table.Ship_Sig)<>""));

This DELETE statement will delete all the records where the WHERE is appropriate. As always, back up your table just in case it eliminates the incorrect data.


That should do it.

anvil19
:eek:
 
Upvote 0

Forum statistics

Threads
1,221,631
Messages
6,160,945
Members
451,679
Latest member
BlueH1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top