Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
select Custid,sum(amount) as total from Sales group by CustID
output of above command
Custid total
1 200
2 800
3 500


Can I store output as table name xyz in my database.
Posted

One easy way is to use INSERT INTO ... SELECT structure. Have a look at SQL INSERT INTO SELECT Statement[^]
 
Share this answer
 
Comments
Shrikesh_kale 18-Feb-15 0:12am    
do know about error String or binary data would be truncated.
Wendelius 18-Feb-15 0:33am    
Sorry but I don't quite understand the question. If the statement fails you will get an error message. The data shouldn't be truncated unless you manipulate it in some way.
Shrikesh_kale 18-Feb-15 1:12am    
name of the column that is too short to hold the data. because of this. above error occur
Umer Akram 18-Feb-15 2:56am    
the query you shared doesn't have a varchar/nvarchar/char column in it.
2ndly you if you use INSERT INTO ... SELECT as Mika suggested. you shouldn't be having this kind of issue.
Wendelius 18-Feb-15 3:38am    
The length of the name of the column doesn't restrict the amount of data that can be stored into the column. It's just a name.

Can you post the code you're currently using?
Procedure 1: You can Use SQL SELECT INTO
Ref.
http://www.w3schools.com/sql/sql_select_into.asp[^]

Procedure 2:
SQL INSERT INTO SELECT Statement
e.g :

SQL
INSERT INTO table2
(Custid,total)
SELECT CustId,Sum(Amount) FROM table1 group by CustId;

Ref.
http://www.w3schools.com/sql/sql_insert_into_select.asp[^]
 
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