Dynamic Insert into table with same name

Alan5896 26 Reputation points
2023-06-14T16:41:55.9933333+00:00
Hello, 
I need help with query that will take all tables with prefix "tifa_" in "centraldb" database and copy all data in same name table that ends with "_hist". Column name should be matched. as_of_date need to be yesterday day when running the query.

I have around 70 tables and this is example of 4 tables -- please see attached

TABLE_NAME COLUMN_NAME

sql



Thank you!
SQL Server Other
{count} votes

2 answers

Sort by: Most helpful
  1. Alan5896 26 Reputation points
    2023-06-14T21:03:35.1+00:00

    Sorry, I do not understand what you are saying.

    I have access only to My SQL and need to write procedure to copy data from tables with a specific prefix to tables with the same name and a suffix. Number of tables every day will be different.

    Can you help me with this?


  2. Alan5896 26 Reputation points
    2023-06-14T21:41:32.25+00:00

    I think if will be answer how to do it in SQL Server then I will convert it to MySQL

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.