Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
insert into #tempmonthly(Duration,occupancy,occupancyGreater4,[adhoc request],[average request],[cut paste percentage],[Total Unique users]) values('FINAL STATISTICS',avg(@occupancy),avg(@occupancy4),sum(@adhocrequestcount),avg(ISNULL(@T_Emp/@TotalDays,0.00)),avg(@cutpaste),sum(isnull(@totalunique_users,0.00)))  

error

why cant i do this ?
Posted
Updated 26-Jun-13 7:22am
v2
Comments
ZurdoDev 26-Jun-13 13:02pm    
Because it is unsupported. Do INSERT INTO ... SELECT ....
Maciej Los 26-Jun-13 13:39pm    
Exactly!
Please, post it as an answer!
Zoltán Zörgő 26-Jun-13 13:22pm    
What is @occupancy exactly?

You need to use:
SQL
INSERT INTO Table1 (Field1, Field2,... FieldN)
SELECT 'FINAL STATISTICS', AVG(Field1), SUM(Field2), AVG(Field3), ... SUM(FieldN)
FROM Table2
GROUP BY ...
 
Share this answer
 
v2
Comments
Maciej Los 26-Jun-13 14:09pm    
+5!
Raja Sekhar S 27-Jun-13 1:13am    
+5.....
Whenever you want to insert data from another table by select query....
then you have to include select query in Insert query...

therefor
query becomes....

SQL
INSERT INTO (Columns......) SELECT Query....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900