I have many tables that all have identical structure and similar table names and am looking for a way to merge a few columns from them all into a new table with two additional columns: an auto-generated integer PK, and the name of the source table. e.g.,
UniqueID SourceID, Xcoord, Ycoord, Zcoord, SourceTable
I managed to create a table containing a list of all the tables I want to use, but don't know what to do next.
SELECT [name]
INTO PointTables
FROM [Surveys].[sys].[tables]
where [name] like '%CoordDB'