Solved

Coding for summary based on a calculated field

Posted on 2011-09-08
2
165 Views
Last Modified: 2012-06-21
I am retrieving data out of a labor billing table.  I have fields available for hours, billing extension, and name. The only missing item is billing rate, which I can get by creating a field using billing extension / hours. I am trying to find the best way to do a single line for each employee for each rate, which is that calculated field. The data would look something like this:

Bill       2 (hours)    100.00(billing extension)   50.00 (Rate)
Bill       1 (hours)       75.00(billing extension)   75.00 (Rate)
Steve   .5(hours)      30.00 (billing extension)  60.00 (Rate)

There could be many detail lines in the data that make up the single summary lines. Not sure what the best way to group these lines together - would be very easy if the billing rate was an actual field, but it is not. Simplified query attached.
select name, (reghrs) as hours, billext, (billext/reghrs) as billrate from LD

group by Name, RegHrs, BillExt

Open in new window

0
Comment
Question by:charkerr6111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 36507954
Hi.

From a performance perspective, you may consider going with a blend between normalization and storing the calculation. You can go for a computed column in SQL. It will be built off of the billext and reghrs columns, but can be indexed that you can then GROUP BY Name, Billrate.

Short of that, you can do this dynamically:
;with LDcte(name, hours, billext, billrate) as (
   select name, reghrs, billext, (billext/reghrs)
   from LD
   -- just to ensure we do not have any divide by zero errors
   where reghrs > 0
)
select name, sum(hours) [hours], sum(billext) [billext], billrate
from LDcte
group by name, billrate
;

Open in new window


Hope that helps!
0
 

Author Closing Comment

by:charkerr6111
ID: 36511593
Perfect!
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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

696 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