tags:

views:

59

answers:

3

how can I assign a column name to the SUM column ?

i.e.

select OwnerUserId, SUM(PostScore)
INTO Experts
from ...

I get this error:

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.

I guess because the column containing the results of SUM has not name.

+4  A: 

First of all there's no SQL Server 2003. Only 2000, 2005 and 2008.

as for the name use AS:

select OwnerUserId, SUM(PostScore) as PostScoreSum
INTO Experts 
from ... 
Mladen Prajdic
A: 

You can alias any column, computed or not by using the AS keyword:

SELECT OwnerUserId AS MyUserId, SUM(PostScore) As Score
INTO Experts
from ...
Oded
+1  A: 
select OwnerUserId, SUM(PostScore) as mySum
INTO Experts
from ...

or

select OwnerUserId, SUM(PostScore) [mySum]
INTO Experts
from ...
Joe Philllips