Solved

!!! Calendar / Date / Array / Query problem

Posted on 2004-10-07
13
316 Views
Last Modified: 2013-12-24
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??
0
Comment
Question by:kkhipple
  • 7
  • 2
  • 2
  • +1
13 Comments
 
LVL 35

Expert Comment

by:mrichmon
Comment Utility
<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....
0
 
LVL 9

Assisted Solution

by:CFDevHead
CFDevHead earned 100 total points
Comment Utility
you might want to try this
SELECT to_char (zdate, 'mm/DD/yyyy hh24:MI') as zdate,
               to_char (time, 'mm/DD/yyyy hh24:MI') as zTime,
               (datediff(minute ,zdate,time) )* 60 as totalHours
               title, id, comments, status, type, user_id
     FROM lieu_events
     WHERE zdate LIKE '%#UCase(DateFormat(ThisCalMonth, "mmm-yy"))#%'
     AND status='APPROVED'
0
 
LVL 5

Author Comment

by:kkhipple
Comment Utility
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>
0
 
LVL 9

Expert Comment

by:CFDevHead
Comment Utility
How would that change, like so?
what do you mean?
0
 
LVL 35

Accepted Solution

by:
mrichmon earned 100 total points
Comment Utility
<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>

Would give results like:
user_id          hoursum          type
123643            10                 overtime
123643            7                   taking time off
658354            5                  taking time off
967562           8                   sick
993422             17               overtime
999231            24               taking time off
etc...
0
 
LVL 5

Author Comment

by:kkhipple
Comment Utility
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
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Author Comment

by:kkhipple
Comment Utility
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"
0
 
LVL 5

Author Comment

by:kkhipple
Comment Utility
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.
0
 
LVL 5

Author Comment

by:kkhipple
Comment Utility
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
0
 
LVL 6

Assisted Solution

by:campbelc
campbelc earned 50 total points
Comment Utility
Can u put together an excel speadsheet showing the layout that you are looking for with some sample data. Much easier to code then.

email it to: badtemper@gmail.com

Thanks.
0
 
LVL 5

Author Comment

by:kkhipple
Comment Utility
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
0
 
LVL 5

Author Comment

by:kkhipple
Comment Utility
These points were distributed for effort.

campbelc you get points for having a badtemper
0
 
LVL 6

Expert Comment

by:campbelc
Comment Utility
lol, thanks
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now