Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 storing the aggregate function values in temporary

Author  Topic 

Swati Jain
Posting Yak Master

139 Posts

Posted - 2007-10-04 : 09:30:24
declare tmp
sum_1 float,
avg_1 float
I tried
insert into tmp values (sum_1 , avg_1)
select sum(col1) as sum_1,avg(col1)as avg_1
then I got the error
The name "sum_1" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
same for "avg_1"

What needs to be done?

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-10-04 : 11:53:18
[code]
declare @foo table(col1 int, col2 int)

insert into @foo

select 1,2 union all
select 3,9 union all
select 6,4 union all
select 3,23 union all
select 8,2 union all
select 3,3

declare @tmp table(sum_1 float,avg_1 float)

insert into @tmp (sum_1 , avg_1)
select sum(col1) ,avg(col1)
from @foo

select * from @tmp
[/code]

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -