Query to print Which Shift based on the time

Need to sort and sum data based on the shifts in our department....
First shift runs from 4:50 am to 2:45 pm, second shift runs from 3:00 pm to 1:00 am and any time in between is the break time.
I cannot get the data to print first shift , break time and second shift correctly
Sample Data :
DROP TABLE TIME_SHIFT CASCADE CONSTRAINTS;
-- TIME_SHIFT (Table)
CREATE TABLE TIME_SHIFT ( TRX_DATE DATE ) ;
Insert into TIME_SHIFT (TRX_DATE) Values (TO_DATE('10/03/2011 10:30:23', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TIME_SHIFT (TRX_DATE) Values (TO_DATE('12/30/2011 11:40:02', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TIME_SHIFT (TRX_DATE) Values (TO_DATE('12/30/2011 23:55:10', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TIME_SHIFT (TRX_DATE) Values (TO_DATE('12/30/2011 16:54:15', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TIME_SHIFT (TRX_DATE) Values (TO_DATE('10/03/2011 10:26:10', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TIME_SHIFT (TRX_DATE) Values (TO_DATE('10/04/2011 00:30:08', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TIME_SHIFT (TRX_DATE) Values (TO_DATE('10/04/2011 02:47:08', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TIME_SHIFT (TRX_DATE) Values (TO_DATE('10/12/2011 15:30:08', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TIME_SHIFT (TRX_DATE) Values (TO_DATE('10/04/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TIME_SHIFT (TRX_DATE) Values (TO_DATE('10/04/2011 12:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TIME_SHIFT (TRX_DATE) Values (TO_DATE('11/22/2011 03:00:00', 'MM/DD/YYYY HH24:MI:SS'));
COMMIT;
SELECT TO_CHAR (trx_date, 'MM/DD/YYYY') ,TO_CHAR (trx_date, 'HH:MI:SSAM')
-- (case
-- when TO_CHAR(trx_date,'HH24:MI:SS') between '04:50:00' and '14:45:00'
-- then 'FIRST SHIFT'
-- when TO_CHAR(trx_date,'HH24:MI:SS') between '15:00:00' and '01:00:00'
-- then 'SECOND SHIFT'
-- else 'BREAK TIME'
-- end
-- ) WHICH_SHIFT
FROM TIME_SHIFT ;
Expected result :
10/03/2011        10:30:23AM     FirstShift
12/30/2011        11:40:02AM     FirstShift
12/30/2011        11:55:10PM     SecondShift
12/30/2011        04:54:15PM     SecondShift
10/03/2011        10:26:10AM     FirstShift
10/04/2011        12:30:08AM     FirstShift
10/04/2011        02:47:08AM     BreakTime
10/12/2011        03:30:08PM     SecondShift
10/04/2011        12:00:00AM     SecondShift
10/04/2011        12:00:00PM     FirstShift
11/22/2011        03:00:00AM             BreakTimeThanks for the help in advance.

Hi,
In everyday speech, when we hear "Between 3:00 PM and 1:00 AM", we understand that it means one range of 10 consecutive hours. That's not how the SQL BETWEEN operator works, however. "x BETWEEN y AND z" in SQL is exactly equivalent to "x >= y AND x <= z". If y < z, it never be TRUE.
Here's one way to do what you want:
SELECT     TO_CHAR (trx_date, 'MM/DD/YYYY')
,     TO_CHAR (trx_date, 'HH:MI:SSAM')
,     CASE
         WHEN  TO_CHAR (trx_date, 'HH24:MI:SS') BETWEEN '04:50:00'
                                              AND         '14:45:00'
         THEN  'FIRST SHIFT'
         WHEN  TO_CHAR (trx_date, 'HH24:MI:SS') BETWEEN '01:00:01'
                                              AND         '14:59:59'
         THEN  'BREAK TIME'
         ELSE  'SECOND SHIFT'
     END               AS which_SHIFT
FROM      time_shift
; This is close to what you tried, which was
(1) see if it's First Shift
(2) if not (1), see if it's Second Shift
(3) if not (1) or (2), it must be Break time
The problem with that is that, as far as SQL is concerned, going just by HH24:MI:SS, the Second shiift is two disjoint periods, and you have to test for each one separately. The query above reverses the last two tests:
(1) see if it's First Shift
(2) if not (1), see if it's Break Time
(3) if not (1) or (2), it must be Second Shift
It would be a little more coding, but perhaps clearer, to do it this way
,     CASE
         WHEN  TO_CHAR (trx_date, 'HH24:MI:SS') BETWEEN '04:50:00'
                                              AND         '14:45:00'
         THEN  'FIRST SHIFT'
         WHEN  TO_CHAR (trx_date, 'HH24:MI:SS') BETWEEN '15:00:00'
                                              AND         '24:00:00' -- or '23:59:59', if you prefer
           OR  TO_CHAR (trx_date, 'HH24:MI:SS') BETWEEN '00:00:00'
                                              AND         '01:00:00
         THEN  'SECOND SHIFT'
         ELSE  'BREAK TIME'
     END               AS which_SHIFT I wish we could mark questions as "Correct" or "Helpful". You provided a good set of sample data in a useable form (you even included DROP TABLE and COMMIT statements), you gave a clear explanation of the problem with the desirred results, and you showed what you had already tried. Lots of people who have used this forum for years haven't learned to do that yet. Keep up the good work!
Don't forget to mention which version of Oracle you're using. In this example, it may not matter. (The query above will work in Oracle 8.1 or higher.) But it never hursts o say something like "I'm using Oracle 10.2.0.3.0".
Edited by: Frank Kulash on Dec 1, 2011 12:23 PM

Similar Messages

  • I have set up my airprint wifi printer which works perfectly with the HP eprint app. However, when i view an email and click on the top right arrow button and select "PRINT" on my ipad nothing happens????...

    I have set up my airprint wifi printer which works perfectly with the HP eprint app. However, when i view an email and click on the top right arrow button and select "PRINT" on my ipad nothing happens????...
    Also, when im viewing websites and i find something i wish to print, same again, if i simply click on the print option at the top right of the screen nothing happens... the only way I can print is if i copy the weblink of the site page then click on my HP eprint app and paste the web link, then select print, it prints off fine.. but its it such a pain to keep copying and pasting links or screen dumping emails just to print...

    Just to recap, this is a collection of ports I have collected over time for people who needed this information when setting up the HP ePrint app so that they could view their email from within the app.  I am certain other applications also need this information.  Although lengthy, I could not find a more comprehensive place to retrieve this information.  Feel free to post additional information, faulty information, or other related topics below as this is simply a collection of data and it would be practically impossible to test all of them. Thank you!
    Don't forgot to say thanks by giving "Kudos" if I helped solve your problem.
    When a solution is found please mark the post that solves your issue.
    Every problem has a solution!

  • I CANNOT PRINT FROM MY IPHONE 4 TO MY BROTHER 8890DW PRINTER WHICH IS CONNECTED TO MY TIME CAPSULE/NETWORK VIA ETHERNET CABLE???

    Why can’t I print from my iPhone 4 to my brother 8890dw printer which is connected to my time capsule/network via ethernet cable???  My iPhone does not even locate my printer,even though I have no problem printing from my Mac to the same printer.

    Typing in all caps indicates shouting, is considered rude and is difficult to read.  Many simply do not read such posts.
    You would need an airprint enabled printer or an app that proides printing function.
    iOS: AirPrint 101

  • Can I print a calander without showing the times of events?

    Can I print a calander without showing the times of events. Or, alternatively, is there a way to list things without having them be an event. Just notes on the day, for instance.

    It seems like a simple solution must be at hand. There is an option in the iCal Preferences (General) panel--Show event times. With this command unchecked the screen view of the month view is free of the times of day, but when I print the month view the times of day are printed.

  • I'm getting an error message "Untrusted Connection" on my on-line bankig site which I use all the time. Now I can't access the site.

    This "Untrusted Connection" is coming up when I try to access my on-line banking site which I use all the time. I also get a OpenDNS message about Phishing and I'm not sure why or what that is. The same thing is happening on my laptop which has Windows 7.

    Did this and it now works.........and I was blaming firefox!!!!!
    ESET: setup -> advanced setup -> extend web and email tree -> SSL
    • SSL protocol: Do not scan SSL protocol

  • Shared printer not working (most of the time)

    I have a Mac Pro running Snow Leopard using a shared Epson R380 printer connected to a G5 (running Leopard) . Most of the time it doesn't work, but occasionally it will. On the Mac Pro, the Epson monitor says "print job accepted" but doesn't change. On the G5, the Epson monitor shows the print job, but says "job stopped". When trying to resume the job, a warning box pops up on the G5 saying "Operation C0uld Not Be Completed - client-error-not-possible".
    The shared printer works fine (most of the time, too) with another networked Mac, a Mac mini G4 running Leopard.
    All OS's are the latest possible.

    Sharing between Leopard and Snowleopard does not work reliably. For this reason, we do not recommend mixing Operating Systems.
    Hope this helps,
    Syd

  • I have three iphones that synchronize with outlook 2010,each with a different profile.Two of them, running ios4.3 succesfully update contacts with the apropriate profile of windows/outlook (which is open at the time). The third iphone using ios 5.1 will a

    I have three iphones that synchronize with outlook 2010,each with a different profile.Two of them, running ios4.3 succesfully update contacts with the apropriate profile of windows/outlook (which is open at the time). The third iphone using ios 5.1 will always sync contacts with the admin account, regardless of the win/outlook account being open.

    I have three iphones that synchronize with outlook 2010,each with a different profile.Two of them, running ios4.3 succesfully update contacts with the apropriate profile of windows/outlook (which is open at the time). The third iphone using ios 5.1 will always sync contacts with the admin account, regardless of the win/outlook account being open.

  • Crystal XI - No Printer option shifts report to the right

    Post Author: yishion
    CA Forum: General
    Hi all, I have encountered a problem which shifts the entire report to the right whenever I check the 'No Printer (optimize for screen display)' option in page setup. Has anyone encountered this problem and is there a working solution to this problem? Thanks in advance.

    Solved my problem. I had to tweak the ODBC drivers on the server.

  • Printing a putaway label at the time of Goods Receipt

    When the Goods Receipt(GR) is done for the stock in interim receiving area (Storage Type 902) then the put-away labels are printed from Transfer Order for GR.
    Users will take the labels and move the materials from staging area to destination bins according to information printed on the label. There should be feature to re-print the labels (from spool – standard SAP function) as and when needed.
    Currently at the IDC location, the following process is utilized; The WMS system produces a putaway label at the time of Goods Receipt. The label print screen in WMS asks for the load ID of the received load and the operator selects label type l and the barcode printer it should print at. The label is automatically printed and sent to a pre-assigned printer. The label is then used to identify the location which the material is to be relocated to from the receiving area, either a picking bin location, or a surplus bin location for storage and replenishment purposes. The label has Job Type, Receipt Date, Quantity, Material Number & Description, Operator I.D., Number of pallets/boxes, Unit of Issue, Serial Number, Destination bin and Load I.D.
    can any one guide me on this!! ASAP

    do you mean when a GR is printed, it shud automatically print the label  as opposed to the manual process now?
    In that case you may have to find a user exit that is triggerred upn saving the GR and call ur label program from there.

  • How to enable a printer which was offline for long time?

    Hi,
    One of our printers has not been used for a long time and was set to be permanently offline. Due to the need of printing, the printer was enabled. It is powered on (and can also be disabled and enabled) but is unable to print.
    Is there anything in SAP to check to see why it is failing to print?
    I have tried to check the status of this printer with other printer which is working fine. There is no difference in between their settings.
    The spool requests are waiting to be printed. I would like to check the ip addresses of the printers. Is it possible to find them through SAP. My O/S is Unix.
    Please help me to find the IP addresses of printers attached through SAP and I will try to check them first.
    Thanks
    Vijay

    Hi Vijay,
    Check SPAD -> output devices
    Check thats the printer is properly setup and it been handled by and active spool server, check that the printer ip-address is correct and the right method is in place.
    You can find the ip address of the printer by doing a ping <name of the printer> in a command prompt.
    Regards
    Juan
    Please reward with points if helpful

  • How can i print a monthly calendar without the times printing?

    I am trying to print an itinerary of an upcoming trip in Ical.  I do NOT want the times to afect either the sorting of events on a particular date or for the Time of day to printed on the calendar.  When I invoke "all-day" Ical sorts alphabetically; when I invoke normal calendar settings, it inovkes times.  All I want to do is provide the hotel, reservation code and activities but I do NOT want to see the time of these entries.  Can I do this in Ical?

    It seems like a simple solution must be at hand. There is an option in the iCal Preferences (General) panel--Show event times. With this command unchecked the screen view of the month view is free of the times of day, but when I print the month view the times of day are printed.

  • I have reinstalled my OS without time machine (using the disc). I want to restore some pictures in the iPhotos which are already in the time machine i was using previously. How can I restore iPhoto from previous time machine?

    My mac book was incredibly slow. When I went to Mac store, they asked me to reinstall the OS with CD and not with the time machine. I reinstalled the operating system. But when I opened the applications, all those started as fresh applications as usual. I have the backup of all other data in another hard disc. But unfortunately, I forgot to copy the photos before reinstallation. I have those photos in my time machine back up. But when I opened time machine, it started like a fresh (very new) time machine and it started backing up my present OS (the reinstalled one). I cannot open the previous time machine, which is in the same hard drive. I wish to open the previous time machine to get the photos which are backed up previuosly. When opened the time machine disc (manually by clicking the icon), i can see all the thigs which I had previously in my macbook. But unfortunately, i cannot access those through time machine! Can anybody help me please?

    How to redownload purchased apps from the App Store

  • How can I print a month calendar without the times of day from the day calendar

    The obvious way to put items into iCal is via the day calendar. But I want to print the calendar as one month to a page and there I do not want the times of day.

    It seems like a simple solution must be at hand. There is an option in the iCal Preferences (General) panel--Show event times. With this command unchecked the screen view of the month view is free of the times of day, but when I print the month view the times of day are printed.

  • How to calculate Goods issue date based on the time of delivery

    Hi SAP Gurus,
    I seek your help/suggestion for the given scenario.
    The user requires calculating the GI date based on time of delivery.
    Based on the delivery priority (like Priority 1= Day 1, Priority 2= Day 2) maintained in customer master, the need is something like below-
    1st case= If Retail Customeru2019s delivery orders received before midday (Noon cut off) require to be dispatched on same working day (Day 1)
    Wholesaler customer delivery orders received before midday require to be dispatched by the next
    Working day (Day 2 Including day of receipt)
    2nd case= Retail customeru2019s delivery orders received after midday require to be dispatched by the next working day
    Wholesaler customer delivery orders received after midday require to be dispatched by on day 3
    Kindly suggest , how to proceed in this. I am new to SAP world so need ur help to tackle this.
    Thanks a lot in advance for the valuable inputs.

    What I proposed to do was,
    a. Create routes like 0 day route, 1 Day route, 2 day route etc.
    b. Route determination is based on the Shipping condition of the customer. Put in the shipping condition for the customer as 00 - immediate delivery. 01 - By Truck, 02 - By Rail, 03 - Ship etc
    c. Now, put in your route determination in such a way that routes change in the sales order with shipping condition (SC). Like, if the shipping condition is set to 00, then 0 day route comes up. Meaning immediate delivery, if SC is 01, then your normal route by truck picks up. etc.
    When the sales order is manually created, you know the time of creation. As route is one of the criteria, the material confirmation happens based on number of days you put in the route to reach the destination. Now that you have the material available for today's delivery, the delivery program can be run to create it, or it can be manually created.
    Now, when you configure the route you have to specify 'Transit duration in calendar days'.
    When you have the sales order created electronically (say thru EDI), then, you may have to ask them to send in shipping condition. Else, you have to modify the function module Idoc_input_orders in such a way that if the sales order creation time is < 12 PM, then put shipping condition as 00, else copy what ever is there in the customer.
    If you do not want to check the time manually when the user creates the sales order, then you may have to use the user exit MV45AFZZ (and I think you can use Save_order_prepare) to check the time and change the shipping condition. By this you will avoid extra coding in Idoc_input_orders and also need not bother if the user changed the route or not.
    Hope my explanation helps.
    Regards,
    Mukund S

  • How do i print my iCal month showing the time

    When I view or print my iCal for the month it shows my appointments but does not give a time.  I would like to see the time so I know when to arrive at my appointment.  Seems simple, but I'm unable to figure it out.  Help please?

    Click on iCal on the toolbar, select Preferences, and check the box for Show Event Times in Month View

Maybe you are looking for

  • Hard drive failed, can I use an external drive as my main HD?

    Took my 20" iMac to the Genius Bar today and my hard drive is completely shot. It would be $250 to replace it but I was wondering if I could run it off of an external hard drive or do I absolutely have to get a new internal drive? Any suggestions or

  • HOW TO - WHERE COLUMN IN (PROCEDURE or FUNCTION)

    Hi. Its posible use Procedure or Function on IN clause?? Example SELECT * FROM TABLE WHERE COLUMN IN (PROCEDURE); or SELECT * FROM TABLE WHERE COLUMN IN (FUNCTION);Thxx for your help! Edited by: Adonias.cl on Oct 12, 2012 9:25 AM

  • ICal time zone on GMT for downloaded calendar invitations

    I have mac OS X 10.7.5. When I download an invite from Evite, or TripIt. The items comes to my iPhone in the correct timezone, but not on my iMac. My iMac defaults to GMT. i have updated the preferecens, added time zone support, and it still loads in

  • ORA-00376: file 30 cannot be read at this time

    hi iam new for appsdba iam facing the below problem can any one help me. [appldev@ebs idev_ebs]$ ./adstrtal.sh apps/apps You are running adstrtal.sh version 115.16 Executing service control script: /devc/p01/oracle/pixcomn/admin/scripts/idev_ebs/adap

  • Roblox Won't Work! Help! Windows 10 Insider Preview

    Please help! I installed Windows 10 today and tried to play Roblox. When I clicked play to a game, it said loading and then the loading things closes and nothing happens....... Help, I want to play, if Windows 10 doesn't support Roblox, then please t