Insert into temp table with Union All in SQL

·

·

,

If you are trying to insert all records from multiple tables to one temp table, the following codes may help.

SELECT *

INTO #RetResult

FROM #TMP1

UNION ALL

SELECT * FROM #TMP2

UNION ALL

SELECT * FROM #TMP3

UNION ALL

SELECT * FROM #TMP4

UNION ALL

SELECT * FROM #TMP5

Review your result:
SELECT * FROM #RetResult



Leave a Reply

Your email address will not be published. Required fields are marked *