Create table with UNION

1

I have this query in Access that I have to pass to SQL Server

INSERT INTO 
    Out_MTK ( Id_MTK, Fijo1, Fijo2)
SELECT 
    Aux_Mtk_Red_Familia.Expr1, Aux_Mtk_Red_Familia.Fijo1, Aux_Mtk_Red_Familia.Fijo2
FROM 
    Aux_Mtk_Red_Familia

The problem is that Aux_Mtk_Red_Family does not exist, it is a UNION of two tables

SELECT 
    * 
FROM
    Aux_Mtk_Red_Familia_Parte1
UNION ALL 
    SELECT 
        * 
    FROM
        Aux_Mtk_Red_Familia_Parte2

How do I make the UNION query create a table for me so that I can concatenate the two queries in one?

    
asked by Alejandro Ricotti 14.02.2017 в 16:27
source

1 answer

1

If the Out_MTK table already exists, you should simply do:

INSERT INTO Out_MTK(Id_MTK, Fijo1, Fijo2)
SELECT * 
FROM Aux_Mtk_Red_Familia_Parte1
UNION ALL 
SELECT * 
FROM Aux_Mtk_Red_Familia_Parte2;

If the table does not exist and you want to create it with the data of that UNION ALL , then use:

SELECT * 
INTO Out_MTK
FROM Aux_Mtk_Red_Familia_Parte1
UNION ALL 
SELECT * 
FROM Aux_Mtk_Red_Familia_Parte2;
    
answered by 14.02.2017 / 16:29
source