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

不想你离开。 提交于 2019-11-28 01:46:05

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;

src: http://www.w3schools.com/sql/sql_select_into.asp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!