Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 calculate total in SQL 2000

Author  Topic 

qutesanju
Posting Yak Master

193 Posts

Posted - 2010-01-11 : 01:50:27
I have 1 query which return multiple row and having 6-8 columns.For the some of columns i want their total at the bottom of that column


Column1 Column2 Column3 Column4 Column5
Abc 10 100 50 120
Def 20 200 45 120
Ghi 30 300 45 120
Total 60 600 140 360

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-01-11 : 03:39:22
Here your Query!

Select Column1, Column2, Column3, Column4, Column5 from table_name
union
select 'Total',sum(Column2), sum(Column3), sum(Column4), sum(Column5) from table_name

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2010-01-11 : 03:51:14
Hi


SELECT *
FROM
(
SELECT 'ABC'AS COLUMN1, 10 AS COLUMN2 ,100 AS COLUMN3,50 AS COLUMN4 ,120 AS COLUMN5 UNION ALL
SELECT 'DEF', 20 ,200 ,45 ,120 UNION ALL
SELECT 'GHI', 30 ,300 ,45 ,120
) AS A
COMPUTE SUM(COLUMN2),SUM(COLUMN3),SUM(COLUMN4),SUM(COLUMN5)



-------------------------
[R][A][J]

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-11 : 07:15:43
I believe COMPUTE isn't available in SQL Server 2000.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-11 : 11:12:09
quote:
Originally posted by webfred

I believe COMPUTE isn't available in SQL Server 2000.


No, you're never too old to Yak'n'Roll if you're too young to die.


Yup its available only from 2005 onwards
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-12 : 01:25:04
quote:
Originally posted by qutesanju

I have 1 query which return multiple row and having 6-8 columns.For the some of columns i want their total at the bottom of that column


Column1 Column2 Column3 Column4 Column5
Abc 10 100 50 120
Def 20 200 45 120
Ghi 30 300 45 120
Total 60 600 140 360



Where do you want to shoe data?
Seems it should be done in Reporting tool

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-12 : 01:44:38
quote:
Originally posted by madhivanan

quote:
Originally posted by qutesanju

I have 1 query which return multiple row and having 6-8 columns.For the some of columns i want their total at the bottom of that column


Column1 Column2 Column3 Column4 Column5
Abc 10 100 50 120
Def 20 200 45 120
Ghi 30 300 45 120
Total 60 600 140 360



Where do you want to shoe data?
Seems it should be done in Reporting tool

Madhivanan

Failing to plan is Planning to fail


most reporting tools have this format built in. In case of SQL reports, its just a matter of giving aggregate expressions in page footer/group footer
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-12 : 01:49:02
quote:
Originally posted by visakh16

quote:
Originally posted by madhivanan

quote:
Originally posted by qutesanju

I have 1 query which return multiple row and having 6-8 columns.For the some of columns i want their total at the bottom of that column


Column1 Column2 Column3 Column4 Column5
Abc 10 100 50 120
Def 20 200 45 120
Ghi 30 300 45 120
Total 60 600 140 360



Where do you want to shoe data?
Seems it should be done in Reporting tool

Madhivanan

Failing to plan is Planning to fail


most reporting tools have this format built in. In case of SQL reports, its just a matter of giving aggregate expressions in page footer/group footer


Yes. Almost every reporting too can support it
But OP didn't specify where the data should be displayed

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -