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
 SQL Server Development (2000)
 columnwise/rowwise total

Author  Topic 

Sarakumar
Posting Yak Master

108 Posts

Posted - 2006-05-18 : 05:15:40

DECLARE @STUDENT TABLE
(
SID INT,
SNAME VARCHAR(20),
MARK1 INT,
MARK2 INT,
MARK3 INT,
MARK4 INT,
MARK5 INT
)



INSERT INTO @STUDENT
select 1,'SONE',80,70,50,60,70 UNION all
select 2,'STWO',60,65,85,76,80 UNION all
select 3,'Sthree',60,65,85,76,80

from the above table i need to get the output columnwise total and rowwise total along with the usual select statment..
1 sone 80 70 50 60 70 330
2 stwo 60 65 85 76 80 326
3 sthree 60 65 85 76 80 326
200 200 220 212 190


is it possible to get this kind of output. how ?

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-05-18 : 05:42:55
Somthing like this


DECLARE @STUDENT TABLE
(
SID INT,
SNAME VARCHAR(20),
MARK1 INT,
MARK2 INT,
MARK3 INT,
MARK4 INT,
MARK5 INT
)



INSERT INTO @STUDENT
select 1,'SONE',80,70,50,60,70 UNION all
select 2,'STWO',60,65,85,76,80 UNION all
select 3,'Sthree',60,65,85,76,80


Select SID,SName,Mark1,Mark2,Mark3,Mark4,Mark5,(Mark1+Mark2+Mark3+Mark4+Mark5) As Total From @Student
Union All
Select '','Horizontal Total',Sum(Mark1),Sum(Mark2),
Sum(Mark3),Sum(Mark4),Sum(Mark5),Sum(Mark1+Mark2+Mark3+Mark4+Mark5) As Total From @Student


If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-18 : 05:46:19
Where do you want to show the data?
If you use Reports make use of Summary Option

Madhivanan

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

Sarakumar
Posting Yak Master

108 Posts

Posted - 2006-05-18 : 05:48:56
Thanks. i will try my requirment with the help of the above code
Go to Top of Page

Sarakumar
Posting Yak Master

108 Posts

Posted - 2006-05-18 : 05:50:48
Output of this SP will get displayed in my
windows forms..
Anyway, the previous post will help me i believe

quote:
Originally posted by madhivanan

Where do you want to show the data?
If you use Reports make use of Summary Option

Madhivanan

Failing to plan is Planning to fail

Go to Top of Page
   

- Advertisement -