473,796 Members | 2,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using SUM in Query to total hours based on Months.

22 New Member
I am using a query to total hours (Cltbudget.CBud hours) and dollars (CltBudget.CBud Fee) Grouped by client names (Cltbudget.CBud CltName).
here is the Query:

SELECT CltBudget.CBudC ltName AS Client
, SUM(CltBudget.C Budfee) AS 'Total Dollars'
, SUM(CltBudget.C Budhours) AS 'Total Hours'
FROM VPM.dbo.CltBudg et CltBudget, CltDue
WHERE CltBudget.CBudD ueID = CltDue.CDID AND ((CltDue.CDTarg et Between '01-01-2007' And '12-31-2008')
AND (CltDue.CDStatu s Not In ('Job Cancelled', 'Delivered', 'Job On Hold')
AND (CltDue.CDCltID Not In (1034,54,1404,1 499))))
GROUP BY CltBudget.CBudC ltName
ORDER BY CltBudget.CBudC ltName

(CltDue.CDTarge t) is the due date for the projects.
here is an example of the output:


Client name Total Dollars Total Hours

I am wanting to be able to Sum the hours for each month as well.

Client name Totaldollars Total Hours jan feb mar etc.

Any help is appreciated, thanks.
Dec 28 '07 #1
1 1732
silversubey
22 New Member
I was able to get this to work woth the following code. If it lokos sloppy, please let me know how to fix it.

SELECT CltBudget.CBudC ltName AS Client
, SUM(CltBudget.C Budfee) AS 'Total Dollars'
, SUM(CltBudget.C Budhours) AS 'Total Hours'
, COUNT(CltBudget .CBudDueID) AS 'Project Count'
, SUM(CASE MONTH(CltDue.CD Target) WHEN 1 THEN CltBudget.CBudH ours ELSE 0 END) AS 'January'
, SUM(CASE MONTH(CltDue.CD Target) WHEN 2 THEN CltBudget.CBudH ours ELSE 0 END) AS 'February'
, SUM(CASE MONTH(CltDue.CD Target) WHEN 3 THEN CltBudget.CBudH ours ELSE 0 END) AS 'March'
, SUM(CASE MONTH(CltDue.CD Target) WHEN 4 THEN CltBudget.CBudH ours ELSE 0 END) AS 'April'
, SUM(CASE MONTH(CltDue.CD Target) WHEN 5 THEN CltBudget.CBudH ours ELSE 0 END) AS 'May'
, SUM(CASE MONTH(CltDue.CD Target) WHEN 6 THEN CltBudget.CBudH ours ELSE 0 END) AS 'June'
, SUM(CASE MONTH(CltDue.CD Target) WHEN 7 THEN CltBudget.CBudH ours ELSE 0 END) AS 'July'
, SUM(CASE MONTH(CltDue.CD Target) WHEN 8 THEN CltBudget.CBudH ours ELSE 0 END) AS 'August'
, SUM(CASE MONTH(CltDue.CD Target) WHEN 9 THEN CltBudget.CBudH ours ELSE 0 END) AS 'September'
, SUM(CASE MONTH(CltDue.CD Target) WHEN 10 THEN CltBudget.CBudH ours ELSE 0 END) AS 'October'
, SUM(CASE MONTH(CltDue.CD Target) WHEN 11 THEN CltBudget.CBudH ours ELSE 0 END) AS 'November'
, SUM(CASE MONTH(CltDue.CD Target) WHEN 12 THEN CltBudget.CBudH ours ELSE 0 END) AS 'December'
FROM VPM.dbo.CltBudg et CltBudget, CltDue
WHERE CltBudget.CBudD ueID = CltDue.CDID AND ((CltDue.CDTarg et between '01-01-2007' AND '12-31-2008')
AND (CltDue.CDStatu s Not In ('Job Cancelled', 'Delivered', 'Job On Hold')
AND (CltDue.CDCltID Not In (1034,54,1404,1 499))))
GROUP BY CltBudget.CBudC ltName
ORDER BY CltBudget.CBudC ltName
Dec 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2091
by: Jamie Pittman via AccessMonster.com | last post by:
I am having trouble bellow wit this query. I have the total regular hours and the overtime. The problem is that if it is 8 hours and under, I need it to show as regular hours. Any thoughts? SELECT ., .Date, ., IIf(<=8,,8) AS , Sum((-)) AS Ot FROM GROUP BY ., .Date, ., IIf(<=8,,8); -- Message posted via http://www.accessmonster.com
5
5591
by: ????? | last post by:
I have an access query which gets data from a number of different tables. Although the tables have primary key fields, the order in which the records are returned means that none of these are in ascending order in the query result set. I need to include in the query a field that numbers the records in the order that they are returned. The numbers must be unique and ascending but do not necessarily have to be consecutive. For Example:
4
5713
by: Stephen Young | last post by:
Hello Have a bit of a problem, im trying to get the total number of hours:minutes for all actions over the month in a query, have tried two methods to no luck... Duration This Month: Format(Sum(.-.),"hh:nn") displays the total hours but rolls over anything over 1 day and starts
1
1871
by: Generale Cluster | last post by:
Hello, I need to extract the names of the employees which have not been active during the last 3 months from the following tables EMPLOYEES: employee_id name COOPERATIVE cooperative_id
2
3998
by: dath | last post by:
Hi, Searched the forum and found a lot on passing form input to aquery but not the other way around. Here is the situation: I have a timesheet form based on a subform query that asks the user for the Month and their last name. The fields in the table being updated include: FY, Month, Employee ID, Task Number, hours. The query then displays the results in data sheet view on the form. I have been asked by users to display total they...
30
3399
by: Noob | last post by:
ftp://ukcassassin:winston@www.ukcassassin.pwp.blueyonder.co.uk/htdocs/Diary%20Form.bmp Hi all I will appologise in advance for my lack of knowledge of access and its working as i am quite new to the program and have been self taught, so here goes. As you can see by the image link i am creating an appointment diary for a garage,its going ok untill i created the "Hours remaing" text box The main subform adds up the hours booked in and...
5
1390
by: bpbull | last post by:
SQL Server 2003 - SQL Query Analyzer. We have a database that stores service tickets and a table called non_part_usage. In this table, we have one field called request_id, one field called line_code_type and one field called quantity (there are more, but these are all we need for this question). Each request_id represents a service ticket. We have two line code types: L for Labor and T for Travel. The quantity field is a number of hours. ...
3
1447
by: flydev | last post by:
Hello, I am trying to build a query that will display the top 5 members of my "virtual airline" based on the total hours flown for the month. Whenever a pilot files a completed flight plan, the data is stored in a table containing the following rows. MID (member ID) hours (hours flown) month (the month of the flight) There will be hundreds of flights per member (or MID).
16
7251
by: Alex30093 | last post by:
OK This is my 1st post to any forum, but I rely on forums all the time. Short story is I find myself needing to become a Access DBA for work. Situation: I want to use one table of events that Track (Employee ID, Employee Name, Event Date and Trip Hours) And be able to add the fields(Week #1, Week #2, Week#3, week #4 and Week #5). *****There is also an Autonumbered (Trip Numebr). What I have tried: I can run this as a query (Employee ID,...
0
9684
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9530
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10236
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10182
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7552
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5445
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.