October 22, 2024
Chicago 12, Melborne City, USA
SQL

Join large set of tables automatically


For data migration, I would like to join tables. There are a lot of tables (more than 100) to be joined and I would like to perform this automatically.
For each of the joins, there exists one target table, but there are a lot of different target tables.
This makes the join look like this:

  • Source A1
  • Source A2
  • Source A3

join to target A.

  • Source B1
  • Source B2

join to target B.
Each source table contains a subset of all columns of the target table. All source and target tables share the same primary keys.
For each join, I already have a list of table names to be joined in variable named
@tableList NVARCHAR(MAX), storing the source table names (e.g. ‘A1,A2,A3’).
How do I create a stored procedure to join the source tables? Preferably, I would like to store the result in a temporary table (per target table) first to inspect the data.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video