Solved

Add a total row in store procedure

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 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

12 Experts available now in Live!

Get 1:1 Help Now