Solved

Performing SUM on GROUP in SQL 2005 Reporting Services

Posted on 2007-04-10
5
6,209 Views
Last Modified: 2010-03-15
I am using SQL 2005 reporting services accessing a SQL 2000 server (I'm going to migrate the data over later).

The program I am having is that I am grouping on a field but when I try and sum on another field, it adds up all of the items instead of those just being displayed.

For example, this would be a collection of records:
partnumber;note;price
part1,note1,5.0
part1,note2,5.0
part1,note3,5.0
part2,note1,3.0
part2,note2,3.0

Well I want it to just sum up the 5 and 3 once and give me 8, instead it give me 21.

I'm looking to just perform a SUM on the items that are actually displayed on the screen.  I have searched all over and found others with similar problems, but no solution.

I have been able to do a SUM just on the ReportItems!textbox.Value, but the problem with that is I can only place the results on header or footer.
0
Comment
Question by:ritetrack
5 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 18885501


do you mean?
select a.partnumber,a.note,sum(case when a.note=b.minnote then a.price else null end) as totalprice
from yourtable as a
inner join (select partnumber,min(note) as minnote from yourtable group by partnumber) as b
 on a.partnumber=b.partnumber
group by a.partnumber,a.note
order by 1,2
0
 

Author Comment

by:ritetrack
ID: 18886439
No, this really needs to be done in the reporting services rather than the SQL statement.  The reason is that in some cases your SQL statement might work, I have other cases that I would group on the item number and only want to grab the value once, but I would want to show the comments in the details.  For example, the results of the report from the original dataset I put might look like:
------------------------------------
part1 - $5
 - note1
 - note2
 - note3

part2 - $3
 - note1
 - note2

Total of parts: $8
------------------------------------
Where this can come more into play is when I have multiple groups (i.e. group by region, then by customer, then show the detail for a customer)
0
 
LVL 2

Accepted Solution

by:
itstheride earned 250 total points
ID: 21345356
not sure if this is what your after...

sum(columnName, "grp_Customer") where "grp_Customer"  is the name of your group. do this on the group footer.


0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

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…
In this article I will describe the Copy Database Wizard 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.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

19 Experts available now in Live!

Get 1:1 Help Now