Solved

Performing SUM on GROUP in SQL 2005 Reporting Services

Posted on 2007-04-10
5
6,212 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Query - which index being used? 2 52
SQL Trigger selecting another database 4 37
SQL Server 2012 express 24 37
display data in text field from data base for updating 6 57
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
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.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

816 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

11 Experts available now in Live!

Get 1:1 Help Now