Solved

!!! Calendar / Date / Array / Query problem

Posted on 2004-10-07
13
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 2
  • 2
  • +1
13 Comments
 
LVL 35

Expert Comment

by:mrichmon
ID: 12253050
<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
ID: 12253095
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
ID: 12253113
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 9

Expert Comment

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

Accepted Solution

by:
mrichmon earned 100 total points
ID: 12253246
<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
ID: 12253254
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
 
LVL 5

Author Comment

by:kkhipple
ID: 12253388
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
ID: 12253404
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
ID: 12253476
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
ID: 12261824
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
ID: 12263115
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
ID: 12263161
These points were distributed for effort.

campbelc you get points for having a badtemper
0
 
LVL 6

Expert Comment

by:campbelc
ID: 12264812
lol, thanks
0

Featured Post

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

724 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