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
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
I'm almost positive that SQL Server doesn't have a CREATE TABLE AS (SELECT... syntax, but you can use SELECT INTO:
SELECT *
INTO JmxMonSer
FROM services
WHERE monitoring_enabled=1
Check the MSDN documentation for proper uses of the CREATE TABLE statement.
Shahid
The below syntax is for using sub-query instead of using static table name... because sometime the required result set is coming from different queries..
SELECT *
INTO JmxMonSer
From (SELECT * FROM services WHERE monitoring_enabled = 1) as X
Hamed2005
Try using SELECT INTO:
SELECT *
INTO newtable [IN externaldb]
FROM table1;
来源:https://stackoverflow.com/questions/11940477/try-to-create-a-table-from-select-sql-server-2008-throws-error