使用子查询选择INTO

时间:2015-09-15 10:43:17

标签: sql-server subquery common-table-expression select-into

关于SQL Server中的SELECT INTO

以下引发错误Incorrect syntax near ')'.

SELECT * INTO Sales.MyTable FROM 
(SELECT TOP(100) * FROM Sales.Customer)

以下内容将通过

With tempCust AS
(
SELECT TOP(100) * FROM Sales.Customer
)
SELECT * INTO Sales.MyTable FROM tempCust

背后的规则是什么?

1 个答案:

答案 0 :(得分:6)

您可以向alias添加subquery,如下所示,然后尝试一下..

SELECT * INTO Sales.MyTable FROM 
(SELECT TOP(100) * FROM Sales.Customer) as abc