Solved

Add a total row in store procedure

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now