Solved

Add a total row in store procedure

Posted on 2008-06-13
3
917 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 142

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 500 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
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.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

810 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