How to move UNION query results to a new table?

Viewed 79695

I have a sample query as shown below:

SELECT     *
FROM         [#temp1]
UNION
SELECT     *
FROM         [#temp2]
UNION
SELECT     *
FROM         [#temp3]
UNION
SELECT     *
FROM         [#temp4]
UNION
SELECT     *
FROM         [#temp5]

How do I move this request of these queries into a new table? Note: My verison of SQL is:

Microsoft SQL Server 2008 (SP1) - 10.0.2531.0 (X64)   Mar 29 2009 10:11:52   Copyright (c) 1988-2008 Microsoft Corporation  Enterprise Edition (64-bit) on Windows NT 6.0 <X64> (Build 6002: Service Pack 2) 

I tried another Stackoverflow answer I found, i.e.

CREATE TABLE managers AS SELECT * FROM employees WHERE desg = 'MANAGER';

But I get an error of : Incorrect syntax near the keyword 'as'.

Here was my full query that failed with the above error:

CREATE TABLE #temp_UNION as


SELECT     *
FROM         [#temp1]
UNION
SELECT     *
FROM         [#temp2]
UNION
SELECT     *
FROM         [#temp3]
UNION
SELECT     *
FROM         [#temp4]
UNION
SELECT     *
FROM         [#temp5]

Any suggestions please on how I'm goofing up?

Thank you, Ray

3 Answers
Related