SELECT * INTO TABLE1
FROM Table2
UNION ALL
SELECT * FROM Table3;
GO
I am using this query to stack two tables together into one table. These tables should have the columns in the exact same order for this query to execute successfully.
I am wondering if there is a trick we can do so that it works regardless of the column order. Is there a way to instruct SQL Server to automatically line up the columns from both tables by name and perform the UNION
?
In SAS, the trick is to write a OUTER UNION CORR
query, for example.
*
.select *
" -- You've more recently said it was OK for "quick ad hoc query". In the interest of fairness, here's my (current) position on the matter