Search code examples
sql-serversql-server-2008create-table

Try to create a table from Select - SqL Server 2008 throws error


Hi I am trying to create a table using inner select statement...

for example:

CREATE TABLE JmxMonSer AS (SELECT * FROM services WHERE monitoring_enabled = 1);

But keep getting error:

Incorrect Syntax near keyword 'AS', Severity 15

please advice


Solution

  • How about:

    SELECT * into JmxMonSer FROM services WHERE monitoring_enabled=1
    

    If the table already exists (and the columns types and ordering line up), you can use:

    INSERT INTO JmxMonSer SELECT * FROM services WHERE monitoring_enabled=1