?
Solved

!!! Calendar / Date / Array / Query problem

Posted on 2004-10-07
13
Medium Priority
?
328 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 400 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
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 
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 400 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 200 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

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…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

649 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