Solved

Add a total row in store procedure

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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