Replace table name or field in a query

Fernando Talvik

New Member
Joined
Jul 30, 2013
Messages
15
Hello guys!

I have a big query with a lots of field and i use it for different tables, but when i have to change the table, i add the new table and them start changing the name of the table manually in every field, and the finally i delete the old table.

Is there a way to change the tables without deleting the field? Is macro de only way??

And also for some fields? for ex: a field in a table has the name "4008i" and in another "4008i", so i have to search manually in the query and in the formula, and this takes a lot of time.

I searched for this matter with no success.

Thank you very much.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Actually, there is an easy way to do this.
Switch your Query to SQL View, and copy and paste it out to something like Microsoft Word.
Then, you can use "Find & Replace" to replace all the tables/fields you want.
Then, copy and paste the SQL code back into a Query SQL code window and save.
That's all there is to it!
 
Upvote 0
Actually, there is an easy way to do this.
Switch your Query to SQL View, and copy and paste it out to something like Microsoft Word.
Then, you can use "Find & Replace" to replace all the tables/fields you want.
Then, copy and paste the SQL code back into a Query SQL code window and save.
That's all there is to it!

I tried this, but it always give "no support for expression JOIN", and before i trade the text, i link the table with the others auxiliary tables.
 
Upvote 0
Are you starting with a properly working query?
There may be an error in the table/field name replacements you are doing, or it could be that the fields in the table names you are replacing are not named exactly the same, so a join won't work after your replacement, because the field name does not exist in the table.

By the way, I use this method all the time with great success.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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