Hi Friend,
As, I want to Result as Calculating Total amount in sql server and, also display one column in DataGridView in window application.
How to write sql query to calculate and also display in datagridview in window application?
Give some sample query for me.
Please any one give immediate solution for me.
Loading
Jignesh TrivediPosted Sep 5, 2012, 2:11 AM
Please refer....
http://www.codeproject.com/Articles/300785/Calculating-simple-running-totals-in-SQL-Server
http://www.databasejournal.com/features/mssql/article.php/3112381/SQL-Server-Calculating-Running-Totals-Subtotals-and-Grand-Total-Without-a-Cursor.htm
sharmila kPosted Sep 17, 2012, 9:54 AM
Thank you for your reply.
Santhosh Kumar JayaramanPosted Sep 6, 2012, 1:56 AM
CREATE TABLE tblPopulation (
Country VARCHAR(100),
[State] VARCHAR(100),
City VARCHAR(100),
[Population (in Millions)] INT
)
INSERT INTO tblPopulation VALUES('India', 'Delhi','East Delhi',9 )
INSERT INTO tblPopulation VALUES('India', 'Delhi','South Delhi',8 )
INSERT INTO tblPopulation VALUES('India', 'Delhi','North Delhi',5.5)
INSERT INTO tblPopulation VALUES('India', 'Delhi','West Delhi',7.5)
INSERT INTO tblPopulation VALUES('Indi', 'Delhi','East Delhi',9 )
INSERT INTO tblPopulation VALUES('Indi', 'Delhi','South Delhi',8 )
INSERT INTO tblPopulation VALUES('Indi', 'Delhi','North Delhi',5.5)
INSERT INTO tblPopulation VALUES('Indi', 'Delhi','West Delhi',7.5)
SELECT Country,[State],City,
SUM ([Population (in Millions)]) AS [Population (in Millions)]
FROM tblPopulation
GROUP BY Country,[State],City
UNION
select Country, 'Total','',SUM ([Population (in Millions)])
FROM tblPopulation
GROUP BY Country
output:
Country State City Population (in Millions)
Indi Delhi East Delhi 7
Indi Delhi North Delhi 7
Indi Delhi South Delhi 7
Indi Delhi West Delhi 7
Indi Total 28
India Delhi East Delhi 9
India Delhi North Delhi 5
India Delhi South Delhi 8
India Delhi West Delhi 7
India Total 29
sharmila kPosted Sep 6, 2012, 1:37 AM
Thank You For your Reply.
This is Coding.
CREATE TABLE tblPopulation (
Country VARCHAR(100),
[State] VARCHAR(100),
City VARCHAR(100),
[Population (in Millions)] INT
INSERT INTO tblPopulation VALUES('India', 'Delhi','East Delhi',9 )
INSERT INTO tblPopulation VALUES('India', 'Delhi','South Delhi',8 )
INSERT INTO tblPopulation VALUES('India', 'Delhi','North Delhi',5.5)
INSERT INTO tblPopulation VALUES('India', 'Delhi','West Delhi',7.5)
SELECT Country,[State],City,
SUM ([Population (in Millions)]) AS [Population (in Millions)]
FROM tblPopulation
GROUP BY Country,[State],City WITH ROLLUP
My OutPut
Country State City
Population (in Millions)India Delhi East Delhi 9
India Delhi North Delhi 5
India Delhi South Delhi 8
India Delhi West Delhi 7
India Delhi NULL 29
India NULL NULL 29
NULL NULL NULL 29
But I want OutPut as this format,
Country State CityPopulation (in Millions)India Delhi East Delhi 9
India Delhi North Delhi 5
India Delhi South Delhi 8
India Delhi West Delhi 7
Total 29
Please any one give immediate solution.