Click here to Skip to main content
15,742,566 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
i have a table with 10 rows, columns are id, name, amount. To count the no of rows, and to sum all amount in single sql query used in c# form how..?
Posted
Comments
Tomas Takac 8-Jan-15 8:23am    
The query is trivial. What exactly is your problem?
select count(id), sum(amount) from mytable

1 solution

Very simple.
SQL
select count(*),sum(amount) from table_name

If this doesn't work then try below query.
SQL
select (select count(*) from table_name) as 'count',(select sum(amount) from table_name) as 'sum of amount'
 
Share this answer
 
Comments
Member 11361354 8-Jan-15 8:48am    
how asign sum and count values to variables
Praveen Kumar Upadhyay 8-Jan-15 8:50am    
Get the query result into the DataSet.
Member 11361354 8-Jan-15 8:56am    
how ? It's not working.
Praveen Kumar Upadhyay 8-Jan-15 8:59am    
Let me know how you are doing it.
Praveen Kumar Upadhyay 8-Jan-15 10:13am    
Someone started devoting all my answers.

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