Member Login

Username
Password
Forget Password
New Sign Up
Search Forum

Buy Support
Incidents

If you can't find your answer in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us private or confidential information:

Click Here
If you can't login and post questions or you are having trouble viewing forum posts:
Click Here
Callback
Support

If you live in USA, UK, Canada, Australia or New Zealand, you can leave us details on your question and request us to call you back and discuss them with you personally  (charges apply).

Click Here
 
Buy Support
Incidents
If you can't find your answer in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us private or confidential information:
Click Here

Forum : TimeTracking query (simple)Search Forum

Forum Home > QODBC - ODBC Driver for QuickBooks > QODBC SQL Support Forum

 New Topic 
 
 Post Reply 
[1]  
 TimeTracking query (simple) 
 Author   Message 
  OrthodoxyUSA 
  
 Group: Members 
 Posts: 7 
 Joined: 2007-08-22 
 Profile
 Posted : 2007-08-22 04:07:41

First of all, Hello everyone!

 

I have been attempting to create a simple SQL query that gives me a list of Jobs and the amount of time spent on that job.

What I have so far is....

SELECT TimeTracking.CustomerRefFullName, TimeTracking.DurationMinutes
FROM Customer Customer, TimeTracking TimeTracking
WHERE Customer.ListID = TimeTracking.CustomerRefListID AND ((TimeTracking.ItemServiceRefFullName Like '%/REG%') AND (Customer.JobStatus='InProgress') AND (TimeTracking.BillableStatus='Billable'))
ORDER BY TimeTracking.CustomerRefFullName

The results look like... (truncated version, my list is 295 records.)

CHOICE/RAINBOW CITY:CH6478 105
CHOICE/RAINBOW CITY:CH6478 480
CHOICE/RAINBOW CITY:CH6478 480
CHOICE/RAINBOW CITY:CH6577 300
CHOICE/RAINBOW CITY:CH6577 180
CHOICE/RAINBOW CITY:CH6577 300
CHOICE/RAINBOW CITY:CH6577 420

I need this list to show each unique job and the total (sum) of time in hours.

That would look like this... (if  my math is correct.)

CHOICE/RAINBOW CITY:CH6478 17.75
CHOICE/RAINBOW CITY:CH6577 20.00

Can you help?

Paul

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2007-08-22 10:43:34

Just use GROUP BY instead of ORDER BY and sum the minutes like this:

SELECT TimeTracking.CustomerRefFullName, sum(TimeTracking.DurationMinutes) as "Total Minutes"
FROM Customer Customer, TimeTracking TimeTracking
WHERE Customer.ListID = TimeTracking.CustomerRefListID AND ((TimeTracking.ItemServiceRefFullName Like '%/REG%') AND (Customer.JobStatus='InProgress') AND (TimeTracking.BillableStatus='Billable'))
GROUP BY TimeTracking.CustomerRefFullName

or for hours:

SELECT TimeTracking.CustomerRefFullName, sum(TimeTracking.DurationMinutes /60) as "Total Hours"
FROM Customer Customer, TimeTracking TimeTracking
WHERE Customer.ListID = TimeTracking.CustomerRefListID AND ((TimeTracking.ItemServiceRefFullName Like '%/REG%') AND (Customer.JobStatus='InProgress') AND (TimeTracking.BillableStatus='Billable'))
GROUP BY TimeTracking.CustomerRefFullName

 

  Top 
  OrthodoxyUSA 
  
 Group: Members 
 Posts: 7 
 Joined: 2007-08-22 
 Profile
 Posted : 2007-08-22 23:01:28

Uh oh... got an error message with that one.

Expected lexical element not found: <Identifier>

I'm using Microsoft Query (11.510.8132) from within Excel 2003

Thanks for your help!

 

 

  Top 
  OrthodoxyUSA 
  
 Group: Members 
 Posts: 7 
 Joined: 2007-08-22 
 Profile
 Posted : 2007-08-23 01:19:59

That works in QReportBuilder... but not in MSQuery

 

Additionally I'm going to need to add another few colums after the Total Hours, which was based on... "(TimeTracking.ItemServiceRefFullName Like '%/REG%')"

One of these additional columns would be for "(TimeTracking.ItemServiceRefFullName Like '%/OT%')"

If I can see how you do one... I'm sure I can do the rest!

Thanks so much for helping me with these simple basic queries that I just am too new to know how to do on my own.

Forgive me...

 

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2007-08-23 08:12:57
Just add the column names with commas between them in the SELECT part before the FROM command. 

  Top 
  OrthodoxyUSA 
  
 Group: Members 
 Posts: 7 
 Joined: 2007-08-22 
 Profile
 Posted : 2007-08-23 09:35:10

Sorry, I wasn't clear

The next column would aso be a.....      sum(TimeTracking.DurationMinutes) as "Overtime"

but the where clause would change by... "(TimeTracking.ItemServiceRefFullName Like '%/OT%')"

 

So how do I do that?

Thanks again.


 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2007-08-23 19:19:32

The simple approach would be to run the overtime as a seperate query.

SELECT TimeTracking.CustomerRefFullName, sum(TimeTracking.DurationMinutes /60) as "Overtime Hours"
FROM Customer Customer, TimeTracking TimeTracking
WHERE Customer.ListID = TimeTracking.CustomerRefListID AND ((TimeTracking.ItemServiceRefFullName Like '%/OT%') AND (Customer.JobStatus='InProgress') AND (TimeTracking.BillableStatus='Billable'))
GROUP BY TimeTracking.CustomerRefFullName

 

  Top 
  OrthodoxyUSA 
  
 Group: Members 
 Posts: 7 
 Joined: 2007-08-22 
 Profile
 Posted : 2007-08-28 23:47:40
I'm sorry to be so much trouble, but I've not been able to come up with the correct query for what I am attempting to do.
 
    The problem comes when I try to make two different columns in the same query based on the same field but having two different values.
 
For instance...
 
    In column one I have a list of all customers who have a Job with [JobStatus]='InProgress' and [BillableStatus]='Billable' (No problems here.)
 
    In column two I want a sum([DurationMinutes]/60) where [ItemServiceRefFullName] like 'REG'.
 
    In column three I want a sum([DurationMinutes]/60) where [ItemServiceRefFullName] like 'OT'.
 
I've not yet to get this to work with any type of query I have designed on any query system... Access, Microsoft Query or QReportBuilder.
 
The below query works properly in Excel Microsoft Query, if I only want the first two columns... adding that third column seems to be my stop point.
 
SELECT TimeTracking.CustomerRefFullName, Sum(TimeTracking.DurationMinutes/60)
FROM Customer Customer, TimeTracking TimeTracking
WHERE Customer.ListID = TimeTracking.CustomerRefListID AND ((TimeTracking.ItemServiceRefFullName Like 'Labor:%%/REG') AND (Customer.JobStatus='InProgress') AND (TimeTracking.BillableStatus='Billable'))
GROUP BY TimeTracking.CustomerRefFullName
 
I tried using the DSum function in Access but that returned the same number repeatedly down columns two and three.
If this has to be done as seperate queries then I don't understand how to join the two queries together to get my final results.
 
 Thanks so much for your help. 
 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2007-08-29 08:42:43

Actually it turns out that combining the two queries is very simple by inserting another group by layer. This allows you to see both Regular (/REG) and Overtime (/OT} hours:-

SELECT TimeTracking.CustomerRefFullName, TimeTracking.ItemServiceRefFullName,
sum(TimeTracking.DurationMinutes /60) as "Total Hours"
FROM Customer Customer, TimeTracking TimeTracking
WHERE Customer.ListID = TimeTracking.CustomerRefListID AND
((TimeTracking.ItemServiceRefFullName Like '%/REG%'
OR (TimeTracking.ItemServiceRefFullName Like '%/OT%')) AND (Customer.JobStatus='InProgress')
AND (TimeTracking.BillableStatus='Billable'))
GROUP BY TimeTracking.CustomerRefFullName, TimeTracking.ItemServiceRefFullName

 

  Top 
  OrthodoxyUSA 
  
 Group: Members 
 Posts: 7 
 Joined: 2007-08-22 
 Profile
 Posted : 2007-08-30 08:44:22

Hello All,

The ultimate solution to this problem using MS Excel 2003 was to create seperate sheets for each query and then use Excel's VLOOKUP() on a sheet to gather all the data together in the correct column format.

Thanks for your help.

 

 

 

 

  Top 
 New Topic 
 
 Post Reply 
[1]  

Jump to