如何为SUM列分配列名?
即
select OwnerUserId,SUM(Postscore) INTO Experts from ...
我收到此错误:
An object or column name is missing or
empty. For SELECT INTO statements,
verify each column has a name. For
other statements,look for empty alias
names. Aliases defined as “” or [] are
not allowed. Change the alias to a
valid name.
我想因为包含SUM结果的列没有名称.
解决方法
首先,没有sql-Server 2003.只有2000,2005,2008(以及2008R2,2012和最新的2014).
至于名称 – 称为别名 – 您可以使用AS.这是标准的sql语法:
SELECT OwnerUserId,SUM(Postscore) AS PostscoreSum INTO Experts FROM ...
但AS是可选的,因此您也可以在没有它的情况下为列添加别名:
SELECT OwnerUserId,SUM(Postscore) PostscoreSum INTO Experts FROM ...
您还可以使用(专有的,仅在sql-Server中)alias = column语法:
SELECT OwnerUserId,PostscoreSum = SUM(Postscore) INTO Experts FROM ...