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 TrivediRank #16 · 50.3K reputationPosted Sep 4, 2012, 10:11 PM EDT
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 k57 reputationPosted Sep 5, 2012, 9:37 PM EDT
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.
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Sep 5, 2012, 9:56 PM EDT
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 k57 reputationPosted Sep 17, 2012, 5:54 AM EDT
Thank you for your reply.