Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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 Column5Abc 10 100 50 120 Def 20 200 45 120Ghi 30 300 45 120Total 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_nameunionselect 'Total',sum(Column2), sum(Column3), sum(Column4), sum(Column5) from table_nameSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/
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 ALLSELECT 'DEF', 20 ,200 ,45 ,120 UNION ALLSELECT 'GHI', 30 ,300 ,45 ,120) AS ACOMPUTE SUM(COLUMN2),SUM(COLUMN3),SUM(COLUMN4),SUM(COLUMN5)
-------------------------[R][A][J]
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.
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
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 Column5Abc 10 100 50 120 Def 20 200 45 120Ghi 30 300 45 120Total 60 600 140 360
Where do you want to shoe data?Seems it should be done in Reporting toolMadhivananFailing to plan is Planning to fail
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 Column5Abc 10 100 50 120 Def 20 200 45 120Ghi 30 300 45 120Total 60 600 140 360
Where do you want to shoe data?Seems it should be done in Reporting toolMadhivananFailing 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
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 Column5Abc 10 100 50 120 Def 20 200 45 120Ghi 30 300 45 120Total 60 600 140 360
Where do you want to shoe data?Seems it should be done in Reporting toolMadhivananFailing 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 itBut OP didn't specify where the data should be displayedMadhivananFailing to plan is Planning to fail