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 2005 Forums
 Transact-SQL (2005)
 Sum of Column in last row of each column

Author  Topic 

Progress2007
Starting Member

17 Posts

Posted - 2009-03-12 : 03:33:10
Hello
My table sturcture is like this

client Column1 Column2 Column3 Column 4 Total
A 10 20 30 40 100
B 20 40 50 60 170
----------------------------------------------------------------
30 60 80 100 170

I want to do this by Stored procudure
one more thing the columns are dynamic.
Now how can i perform this query

asgast
Posting Yak Master

149 Posts

Posted - 2009-03-12 : 04:14:02
if your columns are dynamic, the simplest solution is to use dynamic sql, pass the columns you want to sum as a parameter for the SP. Then use it to make a string and execute it.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-12 : 05:06:26
quote:
Originally posted by Progress2007

Hello
My table sturcture is like this

client Column1 Column2 Column3 Column 4 Total
A 10 20 30 40 100
B 20 40 50 60 170
----------------------------------------------------------------
30 60 80 100 170

I want to do this by Stored procudure
one more thing the columns are dynamic.
Now how can i perform this query




Where do you want to show data?

Madhivanan

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

Progress2007
Starting Member

17 Posts

Posted - 2009-03-12 : 05:22:16
just i want that i coluld able to create a SP with a SQL query
and the result of this Query should bound to a datagrid
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-03-12 : 06:56:41
is this u want
select Column1, Column2, Column3, Column4 from URTABLENAME COMPUTE SUM( Column1),SUM(Column2),SUM(Column3),SUM(Column4)
Go to Top of Page
   

- Advertisement -