473,387 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Using SUM in Query to total hours based on Months.

I am using a query to total hours (Cltbudget.CBudhours) and dollars (CltBudget.CBudFee) Grouped by client names (Cltbudget.CBudCltName).
here is the Query:

SELECT CltBudget.CBudCltName AS Client
, SUM(CltBudget.CBudfee) AS 'Total Dollars'
, SUM(CltBudget.CBudhours) AS 'Total Hours'
FROM VPM.dbo.CltBudget CltBudget, CltDue
WHERE CltBudget.CBudDueID = CltDue.CDID AND ((CltDue.CDTarget Between '01-01-2007' And '12-31-2008')
AND (CltDue.CDStatus Not In ('Job Cancelled', 'Delivered', 'Job On Hold')
AND (CltDue.CDCltID Not In (1034,54,1404,1499))))
GROUP BY CltBudget.CBudCltName
ORDER BY CltBudget.CBudCltName

(CltDue.CDTarget) 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 1711
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.CBudCltName AS Client
, SUM(CltBudget.CBudfee) AS 'Total Dollars'
, SUM(CltBudget.CBudhours) AS 'Total Hours'
, COUNT(CltBudget.CBudDueID) AS 'Project Count'
, SUM(CASE MONTH(CltDue.CDTarget) WHEN 1 THEN CltBudget.CBudHours ELSE 0 END) AS 'January'
, SUM(CASE MONTH(CltDue.CDTarget) WHEN 2 THEN CltBudget.CBudHours ELSE 0 END) AS 'February'
, SUM(CASE MONTH(CltDue.CDTarget) WHEN 3 THEN CltBudget.CBudHours ELSE 0 END) AS 'March'
, SUM(CASE MONTH(CltDue.CDTarget) WHEN 4 THEN CltBudget.CBudHours ELSE 0 END) AS 'April'
, SUM(CASE MONTH(CltDue.CDTarget) WHEN 5 THEN CltBudget.CBudHours ELSE 0 END) AS 'May'
, SUM(CASE MONTH(CltDue.CDTarget) WHEN 6 THEN CltBudget.CBudHours ELSE 0 END) AS 'June'
, SUM(CASE MONTH(CltDue.CDTarget) WHEN 7 THEN CltBudget.CBudHours ELSE 0 END) AS 'July'
, SUM(CASE MONTH(CltDue.CDTarget) WHEN 8 THEN CltBudget.CBudHours ELSE 0 END) AS 'August'
, SUM(CASE MONTH(CltDue.CDTarget) WHEN 9 THEN CltBudget.CBudHours ELSE 0 END) AS 'September'
, SUM(CASE MONTH(CltDue.CDTarget) WHEN 10 THEN CltBudget.CBudHours ELSE 0 END) AS 'October'
, SUM(CASE MONTH(CltDue.CDTarget) WHEN 11 THEN CltBudget.CBudHours ELSE 0 END) AS 'November'
, SUM(CASE MONTH(CltDue.CDTarget) WHEN 12 THEN CltBudget.CBudHours ELSE 0 END) AS 'December'
FROM VPM.dbo.CltBudget CltBudget, CltDue
WHERE CltBudget.CBudDueID = CltDue.CDID AND ((CltDue.CDTarget between '01-01-2007' AND '12-31-2008')
AND (CltDue.CDStatus Not In ('Job Cancelled', 'Delivered', 'Job On Hold')
AND (CltDue.CDCltID Not In (1034,54,1404,1499))))
GROUP BY CltBudget.CBudCltName
ORDER BY CltBudget.CBudCltName
Dec 28 '07 #2

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

Similar topics

3
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? ...
5
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...
4
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:...
1
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
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...
30
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...
5
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...
3
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...
16
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...

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.