Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Add a total row in store procedure

Posted on 2008-06-13
3
Medium Priority
?
948 Views
Last Modified: 2012-05-05
how do Add a total row to in a  store procedure, my query show;
meses enero febreo
item1   100     200
item2   150      250
I need to show
meses enero febreo
item1   100     200
item2   150      250
total     250     450
0
Comment
Question by:enrique_aeo
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21780739
here we go:
select mese, enero, febreo
  from yourtable
union all
select 'total', sum(enero), sum(febro)
  from yourtable

Open in new window

0
 
LVL 8

Expert Comment

by:sbagireddi
ID: 21780744
select sum(enero),sum(febreo)
0
 
LVL 16

Accepted Solution

by:
brad2575 earned 1500 total points
ID: 21780752
You can do a union on the query.

Note you may have to change the word 'total' in the second query so tha tit is ordered properly, you may need to call it 'zztotal' or something so it shows up as the last column in the sort order.

Select meses, enero, febreo From TableName
 
Union
 
Select 'total' as meses, Sum(enero), sum(febreo) From TableName
 
Order by meses

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question