(CASE WHEN TO_CHAR(to_date(lag_dt,'YYYY/MM/DD'),'DY','nls_date_language=english')='SUN' THEN 1 ELSE 0 END) -
(CASE WHEN TO_CHAR(to_date(dt,'YYYY/MM/DD'),'DY','nls_date_language=english')='SAT' THEN 1 ELSE 0 END) as Bus_Days_Diff
from ifsinfo.RW_OUT_ORDERS_HIST_ONE_LAG
Page 1 / 1
Your should have a calendar set up under Site from which you can exclude non-working days.
Here’s how to use the distribution calendar to achieve this. (On our system, this example shows that 5 working days separate last Wednesday and this Wednesday.)
To solve the problem you have with adding HH24:MI:SS to your SQL-statements we need to know the data type of columns DT and LAG_DT in the IAL RW_OUT_ORDERS_HIST_ONE_LAG.
If it is VARCHAR2 or any other string data type we need to know the format of the data. (If data type is DATE there is no specific format.)
here’s the IAL:
SELECT Site, OrderNo, OrderStatus, Status,
TO_CHAR(StatusDate,'yyyy-mm-dd') dt,
LAG(Status) OVER(PARTITION BY OrderNo ORDER BY OrderNo, StatusDate) lag_status,
TO_CHAR(LAG(StatusDate) OVER(PARTITION BY OrderNo ORDER BY OrderNo, StatusDate),'yyyy-mm-dd') lag_dt,
StatusDate - LAG(StatusDate) OVER(PARTITION BY OrderNo ORDER BY OrderNo, StatusDate) diff
FROM ifsinfo.RW_OUT_ORDERS_HIST_ONE_STS coh
order by Site, OrderNo, Status
here’s some resulting data:
So are you saying in order to get HH:MM:SS we should use VARCHAR2() instead of TO_CHAR()?
Thanks for the minutes API, that could be helpful.
The example doesn’t have HH:MM:SS included in the example so it’s not useful; we need # of hours between two full dates YYYY-MM-DD HH:MM:SS, excluding weekends.
Good information, now I see the problem.
The columns DT and LAG_DT in the IAL are already strings on format YYYY-MM-DD so they do not contain the timestamp.
The cleanest way seems to be to remove the to_char in the IAL to get the two columns as data type DATE.
SELECT Site, OrderNo, OrderStatus, Status, StatusDate dt, LAG(Status) OVER(PARTITION BY OrderNo ORDER BY OrderNo, StatusDate) lag_status, LAG(StatusDate) OVER(PARTITION BY OrderNo ORDER BY OrderNo, StatusDate) lag_dt, StatusDate - LAG(StatusDate) OVER(PARTITION BY OrderNo ORDER BY OrderNo, StatusDate) diff FROM ifsinfo.RW_OUT_ORDERS_HIST_ONE_STS coh ORDER BY Site, OrderNo, Status
Then you do not need the to_date in your SQL and can send in the columns directly into “Work_Time_Calendar_API.Get_Work_Minutes_Between”.
What I meant with VARCHAR2 was an example of a string data type. All columns in your IAL view has a data type and if you do a to_char on a column with data type DATE the data type will be VARCHAR2.
Example:
awesome, thx!
I tried it and it works, however it looks like the minutes are low. Look at the first row. There are 17.6 days (including weekends); then 13 work days w/o weekends, yet the Hours (I took the minutes / 60) is only 111.18, when it should be around 13.6 * 24 = 326.4 hours.
What am I missing?
The problem is that the calendar you have as Distribution Calendar in your site does only have work time for 8 hours a day.
You could check and see on the site which calendar you have and then go to this window to see the generated work minutes per day:
You must use another calendar which has 24 hours per day.
great, thx. Turns out we do have a calendar like that- named ‘5-24’. I plugged that in and now it works. Thx so much!
ROUND(work_time_calendar_api.get_work_minutes_between('5-24',lag_dt,dt) / 60, 2) as Bus_Hrs_API
When I try to put the API call in the IAL I get this error. I do have it prefaced with &A)..
I figured it out; I need two periods, not one, after &AO.