SELECT INTO USING UNION QUERY SELECT INTO USING UNION QUERY sql-server sql-server

SELECT INTO USING UNION QUERY


You have to define a table alias for a derived table in SQL Server:

SELECT x.*   INTO [NEW_TABLE]  FROM (SELECT * FROM TABLE1        UNION        SELECT * FROM TABLE2) x

"x" is the table alias in this example.


You can also try:

create table new_table asselect * from table1unionselect * from table2


INSERT INTO #Temp1SELECT val1, val2 FROM TABLE1 UNIONSELECT val1, val2FROM TABLE2