Sql – Is it possible to use the SELECT INTO clause with UNION [ALL]

sqlsql server

In SQL Server this inserts 100 records, from the Customers table into tmpFerdeen :-

SELECT top(100)*
INTO tmpFerdeen
FROM Customers

Is it possible to do a SELECT INTO across a UNION ALL SELECT :-

SELECT top(100)* 
FROM Customers
UNION All
SELECT top(100)* 
FROM CustomerEurope
UNION All
SELECT top(100)* 
FROM CustomerAsia
UNION All
SELECT top(100)* 
FROM CustomerAmericas

Not too sure where to add the INTO clause.

Best Answer

This works in SQL Server:

SELECT * INTO tmpFerdeen FROM (
  SELECT top 100 * 
  FROM Customers
  UNION All
  SELECT top 100 * 
  FROM CustomerEurope
  UNION All
  SELECT top 100 * 
  FROM CustomerAsia
  UNION All
  SELECT top 100 * 
  FROM CustomerAmericas
) as tmp