If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Change syntax from Update Case Statement to Update Union Statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-10-11, 20:32
newphpcoder newphpcoder is offline
Registered User
 
Join Date: Dec 2010
Posts: 126
Change syntax from Update Case Statement to Update Union Statement

Good day!

Theirs a programmer told me that could I used Union Statement to solve my issue in my query, but i can't imagine how can I do that, because my query I used case statement, I have no idea how can I used union instead of case statement.

Here is my problem, I need to get the rendered hours and the rendered hours should be only 8 hours or less 8 hours if the employee was time in late.

I have 3 shifts 21:35 - 05:35, 05:35- 13:35, 13:35-21:35

using case statement it works only in one shift, I want to get the rendered with different scheduled.

Like for example :
Employee 1 time in = 21:00 time out = 05:40 the rendered = 8 hours only event he time in early and time out late it only compute the 21:35 - 05:35
Employee 2 time in = 06:35 time out = 13:50 the rendered should be = 7 hours only because he was late 1 hour because his schedule is 05:35 but he time in 06:35 even he time out late its not considered because only time from 05:35-13:35 will get
Employee 3 time in = 13:35 time out = 24:35 the rendered should be = 8 only even he timeout late.

Rendered should be compute only the 8 hours of work, no matter he time out late only 8 hours would be get based on their schedule. and subtrace if he time in late.

here is my syntax in case statement:

PHP Code:
UPDATE employee SET rendered sec_to_time(time_to_sec('08:00:00') + 
            case 
              
when time_to_sec(time(timein)) < time_to_sec('21:35:00'then 0
              
else time_to_sec('21:35:00') - time_to_sec(time(timein))
            
end +
            case 
              
when time_to_sec(time(timeout)) > time_to_sec('05:35:00'then 0
              
else time_to_sec(time(timeout)) - time_to_sec('05:35:00')
            
end
it is only for one shift and it works, but when I tried this to get the rendered for 3 shifts:

PHP Code:
UPDATE employee SET rendered sec_to_time(time_to_sec('08:00:00') + 
            case 
              
when time_to_sec(time(timein)) < time_to_sec('21:35:00'then 0
              
else time_to_sec('21:35:00') - time_to_sec(time(timein))
            
end +
            case 
              
when time_to_sec(time(timeout)) > time_to_sec('05:35:00'then 0
              
else time_to_sec(time(timeout)) - time_to_sec('05:35:00')
            
end +
case 
              
when time_to_sec(time(timein)) < time_to_sec('05:35:00'then 0
              
else time_to_sec('05:35:00') - time_to_sec(time(timein))
            
end +
            case 
              
when time_to_sec(time(timeout)) > time_to_sec('13:35:00'then 0
              
else time_to_sec(time(timeout)) - time_to_sec('13:35:00')
            
end +
    case 
              
when time_to_sec(time(timein)) < time_to_sec('13:35:00'then 0
              
else time_to_sec('13:35:00') - time_to_sec(time(timein))
            
end +
            case 
              
when time_to_sec(time(timeout)) > time_to_sec('21:35:00'then 0
              
else time_to_sec(time(timeout)) - time_to_sec('21:35:00')
            
end
); 
wrong output was displayed.

If UNION Statement is the solution? How? Thank you

Is there any query can i used? I really need to solved this .

Any help is highly appreciated.

Thank you so much
Reply With Quote
  #2 (permalink)  
Old 11-10-11, 21:31
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by newphpcoder View Post
Theirs a programmer told me that could I used Union Statement to solve my issue in my query, but i can't imagine how can I do that...
so go back to that programmer and ask how
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-10-11, 23:59
newphpcoder newphpcoder is offline
Registered User
 
Join Date: Dec 2010
Posts: 126
He did not response when I ask how :(
Reply With Quote
  #4 (permalink)  
Old 11-11-11, 02:18
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
you need a new programmer then
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 11-11-11, 02:29
newphpcoder newphpcoder is offline
Registered User
 
Join Date: Dec 2010
Posts: 126
Quote:
Originally Posted by r937 View Post
you need a new programmer then :D
Can you help me???

Thank you
Reply With Quote
  #6 (permalink)  
Old 11-11-11, 02:38
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
i think you need a new field which indicates which shift an employee is on
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 11-11-11, 02:49
newphpcoder newphpcoder is offline
Registered User
 
Join Date: Dec 2010
Posts: 126
Yes, now i add field for shift and I use:

data 1 for 21:35 - 05:35
data 2 for 05:35 - 13:35
data 3 for 13:35 - 21:35
data 4 for 08:00 - 08:00

and now, how can I used shift field to get the rendered?

Thank you
Reply With Quote
  #8 (permalink)  
Old 11-11-11, 02:51
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
i'm not going to continue to post to two completely identical threads on this site and on another site
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 11-11-11, 02:59
newphpcoder newphpcoder is offline
Registered User
 
Join Date: Dec 2010
Posts: 126
Okay, Thank you
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On