有没有可能在UNION 中使用SELECT INTO子句?
在SQL Server中,这将从Customers表中插入100条logging到tmpFerdeen中: –
SELECT top(100)* INTO tmpFerdeen FROM Customers
是否有可能通过UNION ALL SELECT做SELECT INTO: –
SELECT top(100)* FROM Customers UNION All SELECT top(100)* FROM CustomerEurope UNION All SELECT top(100)* FROM CustomerAsia UNION All SELECT top(100)* FROM CustomerAmericas
不太确定在哪里添加INTO子句。
这在SQL Server中工作:
SELECT * INTO tmpFerdeen FROM ( SELECT top 100 * FROM Customers UNION All SELECT top 100 * FROM CustomerEurope UNION All SELECT top 100 * FROM CustomerAsia UNION All SELECT top 100 * FROM CustomerAmericas ) as tmp
你根本不需要派生表。
在第一个SELECT
后面放上INTO
SELECT top(100)* INTO tmpFerdeen FROM Customers UNION All SELECT top(100)* FROM CustomerEurope UNION All SELECT top(100)* FROM CustomerAsia UNION All SELECT top(100)* FROM CustomerAmericas
SELECT * INTO tmpFerdeen FROM (SELECT top(100)* FROM Customers UNION All SELECT top(100)* FROM CustomerEurope UNION All SELECT top(100)* FROM CustomerAsia UNION All SELECT top(100)* FROM CustomerAmericas) AS Blablabal
这个“Blablabal”是必要的
对于MS Access查询,这工作:
SELECT * INTO tmpFerdeen FROM( SELECT top(100) * FROM Customers UNION All SELECT top(100) * FROM CustomerEurope UNION All SELECT top(100) * FROM CustomerAsia UNION All SELECT top(100) * FROM CustomerAmericas )
这在MS Access中不起作用
SELECT top(100) * INTO tmpFerdeen FROM Customers UNION All SELECT top(100) * FROM CustomerEurope UNION All SELECT top(100) * FROM CustomerAsia UNION All SELECT top(100) * FROM CustomerAmericas
也许试试这个?
SELECT * INTO tmpFerdeen ( SELECT top(100)* FROM Customers UNION All SELECT top(100)* FROM CustomerEurope UNION All SELECT top(100)* FROM CustomerAsia UNION All SELECT top(100)* FROM CustomerAmericas)
尝试这样的:使用联合的结构创build最终的对象表,tmpFerdeen。
然后
INSERT INTO tmpFerdeen ( SELECT top(100)* FROM Customers UNION All SELECT top(100)* FROM CustomerEurope UNION All SELECT top(100)* FROM CustomerAsia UNION All SELECT top(100)* FROM CustomerAmericas )