Link to home
Start Free TrialLog in
Avatar of kkhipple
kkhipple

asked on

!!! Calendar / Date / Array / Query problem

Here's the app def:  
Its an approval site for time. User enters how much hours they worked overtime.
Manager logs on and can approve or reject.

Current Situation:

I need to be able to add the number of hours for each day and print it out for that day for each employee

I have the following query:

<!--- grabs all approved users info --->
<CFQUERY DATASOURCE="lieu" NAME="lookup">
      SELECT to_char (zdate, 'mm/DD/yyyy hh24:MI') as zdate,
                  to_char (time, 'mm/DD/yyyy hh24:MI') as zTime,
                  title, id, comments, status, type, user_id
      FROM lieu_events
      WHERE zdate LIKE '%#UCase(DateFormat(ThisCalMonth, "mmm-yy"))#%'
      AND status='APPROVED'
</CFQUERY>



How do I alter the SQL statement so that it sums up the number of hours entered (zdate - time) per day for each user_id??
Avatar of mrichmon
mrichmon

<CFQUERY DATASOURCE="lieu" NAME="lookup">
     SELECT SUM(Datediff(h, zdate, time)) AS hoursum, user_id
     FROM lieu_events
     WHERE zdate LIKE '%#UCase(DateFormat(ThisCalMonth, "mmm-yy"))#%'
     AND status='APPROVED'
     GROUP BY user_id
</CFQUERY>

That should do it.

If you still need other columns just add them to both the select and group by....
SOLUTION
Avatar of CFDevHead
CFDevHead

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kkhipple

ASKER

Thx for responding mrichmon.
Btw, there is also a type table field.
This indicates what kind of request. Overtime or Taking time off.

How would that change, like so?

<CFQUERY DATASOURCE="lieu" NAME="lookup">
     SELECT SUM(Datediff(h, zdate, time)) AS hoursum, user_id, type
     FROM lieu_events
     WHERE zdate LIKE '%#UCase(DateFormat(ThisCalMonth, "mmm-yy"))#%'
     AND status='APPROVED'
     GROUP BY user_id, type
</CFQUERY>
How would that change, like so?
what do you mean?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I mean, if on one day within the month .... the user - for whatever reason - decides to input two requests for time taken off or overtime then i'd like to sum up the hours of time taken off separately and overtime worked separately within one particular day for each user.


is that too cryptic?  i hope someone can figure out what im trying to say
Here's the table definition:

 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 ID                                                 VARCHAR2(8)
 USER_ID                                            VARCHAR2(6)
 ZDATE                                              DATE
 TIME                                               DATE
 TITLE                                              VARCHAR2(75)
 COMMENTS                                           VARCHAR2(200)
 STATUS                                             VARCHAR2(50)
 TYPE                                               VARCHAR2(25)


Im' getting the following error:

ORA-00904: invalid column name

SQL = "SELECT SUM(Datediff(h, zdate, time)) AS hoursum, user_id FROM lieu_events WHERE zdate LIKE '%OCT-04%' AND status='APPROVED' GROUP BY user_id"
mind you, I also would like it so that it sums up the hours for each day.  

is the query doing that?

<CFQUERY DATASOURCE="lieu" NAME="lookup">
     SELECT SUM(Datediff(h, zdate, time)) AS hoursum, user_id, type
     FROM lieu_events
     WHERE zdate LIKE '%#UCase(DateFormat(ThisCalMonth, "mmm-yy"))#%'
     AND status='APPROVED'
     GROUP BY user_id, type
</CFQUERY>


from what it seems, its summing up the hours for whatever zdate im passing it. which in this case, is the first of the month.
if that's too difficult... once the query is working.. should i itterate through the query and input the values into an array?  if so, how would i do that?


sorry guys.. but i need to get this done ASAP  

KDK
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
haha.... nice email addy campbelc / badtemper ...  

well i got it figured out ... and although none of you were able to guide me in the right direciton. possibly because i didn't explain properly... i will give a few of you that did attempt to help me out  points....


KDK
p.s.  i couldn't get the group by thing going for my particular problem... so used an array to store unqiue user_id ... and then looped thru and added the hrs ...  if anyone wants to see the code... let me know
These points were distributed for effort.

campbelc you get points for having a badtemper
lol, thanks