How to get the next working date?

Hi,
I need to extract data between the 2nd of the month, and second working date of the following month.
Here is the code I have to check if the date is a weekend, and check if it is in the Holidays table (for UK Holidays):
(This code is to check against Easter 2014, so Good Friday was on the 18th of April, Easter Monday was on the 21st, and the date I want returned is Tuesday the 22nd but I cannot get it working correctly).
declare @LatestDate datetime
set @LatestDate = DATEADD(m,-9,getdate()) -- cast('01/11/2014' as datetime) --dateadd(m,1,datediff(d,0,'01/11/2014'))
set @LatestDate = DATEADD(d,13,@LatestDate)
print @LatestDate
if datepart(dw,@LatestDate) in (1,7)
Begin
while datepart(dw,@LatestDate) in (1,7)
OR
exists (select * from Hermes_Rep..Holidays where Holiday =right(CONVERT(CHAR(10), @LatestDate, 101),4) + '-' + left(CONVERT(CHAR(15), @LatestDate, 101),2) + '-' + SUBSTRING(CONVERT(CHAR(15), @LatestDate, 101),4,2))
Begin
set @LatestDate=DATEADD(d,1,@LatestDate)
End
End
What I need is for my code to always return the 2nd working day of any month, taking into account weekends, and Holidays in the Holidays table.
The Holidays table has dates in the format '2014-04-18 00:00:00' (for Good Friday 2014)

Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI-ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI-ISO Standard SQL. And you need to read and download the PDF for: 
https:--www.simple-talk.com-books-sql-books-119-sql-code-smells-
>>Here is the code I have to check if the date is a weekend, and check if it is in the Holidays table (for UK Holidays): <<
Do you know what a calendar table is?
>> (This code is to check against Easter 2014, so Good Friday was on the 18th of April, Easter Monday was on the 21st, and the date I want returned is Tuesday the 22nd but I cannot get it working correctly). <<
Catholic or Orthodox Easter?  This is one of many reasons we do not use computations in SQL. What you did is the wrong approach  done with bad programming. For example, we do not use the old Sybase getdate() now. The only display format allowed in
ANSI/ISO Standard SQL, but you used a local dialect! 
COBOL treats dates as strings like you did; SQL has a temporal data type. 
>> What I need is for my code to always return the 2nd working day of any month, taking into account weekends, and Holidays in the Holidays table. <<
The idea of a Holiday table is bad; why are these dates totally different entities from other dates? Would you split Personnel on sex and have “Male_Personnel” and “Female_Personnel”? 
The Julian business day is a good trick. Number the days from whenever your calendar starts and repeat a number for a weekend or company holiday.
CREATE TABLE Calendar
(cal_date DATE NOT NULL PRIMARY KEY, 
 julian_business_nbr INTEGER NOT NULL, 
INSERT INTO Calendar 
VALUES ('2007-04-05', 42), 
 ('2007-04-06', 43), -- good Friday 
 ('2007-04-07', 43), 
 ('2007-04-08', 43), -- Easter Sunday 
 ('2007-04-09', 44), 
 ('2007-04-10', 45); --Tuesday
To compute the business days from Thursday of this week to next
 Tuesdays:
SELECT (C2.julian_business_nbr - C1.julian_business_nbr)
  FROM Calendar AS C1, Calendar AS C2
 WHERE C1.cal_date = '2007-04-05',
   AND C2.cal_date = '2007-04-10'; 
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • How to get the next FACTORYDATE

    Hello all,
    Can somebody show me how to get the next (FACTORYDATE) from SAP in the objective to check and validate the shipto date in the ISA b2b application.
    Thanks in advance.

    Hi Manuel,
    my email: [email protected]
    thank you in advance,
    Djamel.

  • How to get the user entered data?

    Hi all,
    I have created an HTMLB DynPage component.
    In That i have created my input screen with textboxes using response.write method.
    i have added one onConfirm event on which the data whould validate.
    so onConfirm method im trying to get the data with request.getParameter method which returns null...
    how to do...how to get the user entered data to do my validations...can anyone plz advice.
    Thanks,
    Viswes

    Hi
    inputfield or textbox component entered directly using response.write(...) are not htmlb , but html.
    to create portal input field (ie HTMLB), you should do something like
    this in the doProcessBeforeOutput member function
    InputField field1 = new InputField("Id1");
    field1.setSize(8); // 8 characters
    this.getForm().addComponent(field1);
    and in doProcessAfterInput member function
    InputField field1 =
    (InputField) this.getComponentByName("Id1");
    you can then manipulate the content of the field.
    Hope this help,
    Guillaume

  • How to get the Next Material Document Number

    Hi,
    Please let me know How to get the next Material Document Number using Functional Module,
    Material Document number are  in MSEG table.
    Regards,
    Ganesh

    Hi Ganesh,
    if you want the next matrial number then first of all you have to define it as a number range in transaction snro.After creating the number range you have to define the interval.
    now you can use your number range by calling the function module
    CALL FUNCTION 'NUMBER_GET_NEXT'
          EXPORTING
            nr_range_nr             = '01' " here you have to give the number range number which you have defined in number range
            object                  = 'ZPRODLOG' " Number Range
          IMPORTING
            number                  = wa_prod_error_log-seqnr " sequence number generated,in your case material number field
          EXCEPTIONS
            interval_not_found      = 1
            number_range_not_intern = 2
            object_not_found        = 3
            quantity_is_0           = 4
            quantity_is_not_1       = 5
            interval_overflow       = 6
            buffer_overflow         = 7
            OTHERS                  = 8.
    each and every time next number will get generated .
    i hope this will help you.
    Thanks,
    Tanmaya

  • TA48312 i have mac os x version 10.4.11 i have no idea how to get the next update because my computer wont do it on its own.

    i have mac os x version 10.4.11 i have no idea how to get the next update because my computer wont do it on its own.

    10.4.11 is as far as you can go with Tiger.  You have to pay for the next update.  It is not available via Software Update.  Depending on which Mac you have, it can be Leopard, Snow Leopard, or Lion.

  • Problem when try to get the next refresh date of a materialized view

    I have a materialized view set to auto refresh(e.g hourly), I need to query this date and display in the report. I create a procedure which return the NEXT_DATE from the ALL_REFRESH_CHILDREN table, the procedure and the view all in schema HK3XDDB.
    If I login as sys, dba in the sql plus and query the procedure, it return the next date, but if I login as normal user which has permission to execute all procedures, it didn't return anything, so I change ALL_REFRESH_CHILDREN to USER_REFRESH_CHILDREN, still no luck. But the details from the USER_MVIEWS can be returned, just won't return anything in the REFRESH one. How to query the next date out?
    Another strange thing is, if I login as sys dba, it return the next date, but if I use a select next_date into statement in the procedure it will throw a data not found error.
    I stuck here for several hours just can't figure it out, any suggestions are welcome,
    Cheers

    Thank you for the reply. It's same with USER_REFRESH_CHILDREN, I can get the result when I run the procedure in SQL PLUS login as sys dba, but if I run the procedure using normal user which has permission to run any procedure, then nothing return. It might be a permission problem but I just can't figure out why.
    Let me explain in detailed:
    Schema HKXDDB, this schema has procedure TestProcedure, in the procedure, I have two ref cursor return, one is for select * from USER_JOBs (or from USER_REFRESH_CHILDREN, I have tried both), one is for select * From USER_MVIEWS, this schema has the materialized view. User HKDWUser has permission to run any procedures, so when this user run the TestProcedure which is own by HKXDDB, the cursor that select from USER_MVIEWS can return results which are materialized views owned by HKXDDB, but the cursor that select form USER_JOBS or USER_REFRESH_CHILDREN always return no rows.
    Any permission I need to assign to HKDWUSER to get the jobs or fresh group that owned by HKXDDB?
    Cheers

  • How to get the materials consumption data

    Hi expert,
    My requirement is to show the material ordered, material received,material consumption,material stock against project definition...
    1. I got the materials ordered and material received against PO of that Project definition but they tell to show the materials got
    from another sites for that project definition.
    2. I have the mseg table for all datas for materials consumption and materials got from another sit e. i know only movement types and WBS
    .if i fetch the data from mseg using movement type and WBS means its not working.i dono how to get the materials consumption
    and materials got from another site.
    They seeing an entires in cji3 based on movement type and storage location.so only i tried to fetch data from mseg table using movement type and WBS
    but its not working.
    please tell ur views to get the data .
    Regards,
    Rathish

    hi,
    In MM module, one Tcode named MMBE will show you the material' information...
    However, from your description, PS/MM will be involved.The cluster table MSEG does hold the data of transaction...

  • Getting the next valid date (jump holidays and weekends)

    Hello,
    I have a column table where I have all holidays of the year in the format "yyyymmdd,yyyymmdd,...", for example, "20091012,20091225".
    I'd like to do a query where I pass a date and a increment of days and it returns the next valid date, excluding weekends and the holidays that I have in the column holidays that I show above.
    P.S: Instead of pass a date and a increment of days, I could pass just a already incremented date, and this query just validate this date, adding 2 days for each weekend and one day for each holiday.
    Is there a way to do that?
    Thanks

    Hi,
    Ranieri wrote:
    Hello,
    I have a column table where I have all holidays of the year in the format "yyyymmdd,yyyymmdd,...", for example, "20091012,20091225".Dates should always be stored in DATE columns. If you really want to, your can also store the formatted date in a separate column.
    I'd like to do a query where I pass a date and a increment of days and it returns the next valid date, excluding weekends and the holidays that I have in the column holidays that I show above.For convenience, you can't beat a user-defined function, such as Etbin's.
    If you really want a pure SQL solution, you can
    (a) generate a list of all the days that might be between the start date and end date (sub-query all_days below)
    (b) outer join that to your holiday table (sub-query got_dnum, below)
    (c) rule out the holidays and weekends (sub_query got_dnum, WHERE clause)
    (d) return the nth remaining day (main query below)
    WITH     all_days     AS
         SELECT  TO_DATE (:start_date, 'DD-Mon-YYYY') + LEVEL     AS dt
         FROM     dual
         CONNECT BY     LEVEL <= 3           -- 3 = max. consecutive non-work days
                   + (:day_cnt * 7 / 4)     -- 4 = min. work days per week
    ,     got_dnum     AS
         SELECT     a.dt
         ,     ROW_NUMBER () OVER (ORDER BY a.dt)     AS dnum
         FROM          all_days     a
         LEFT OUTER JOIN     holidays     h     ON     a.dt = TO_DATE (txt, 'YYYYMMDD')
         WHERE     h.txt               IS NULL
         AND     TO_CHAR (a.dt, 'Dy')      NOT IN ('Sat', 'Sun')
    SELECT     dt
    FROM     got_dnum
    WHERE     dnum     = :day_cnt
    ;This assumes :day_cnt > 0.
    The tricky part is estimating how far you might have to go in sub-query all-days to be certain you've included at leas :day_cnt work days.
    Where I work, holidays are always at least 7 days apart.
    That means that there can be, at most, 3 consective days without work (which happens when there is a holiday on Monday or Friday), and that thee are at least 4 work days in any period of 7 consecutive days. That's where the "magic numbers" 3 and 4 come from in the CONNECT BY clause of all_days. Depending on your holidays, you may need to change those numbers.
    P.S: Instead of pass a date and a increment of days, I could pass just a already incremented date, and this query just validate this date, adding 2 days for each weekend and one day for each holiday.Good thought, but it won't quite work. How do you know how many holidays were in the interval? And what if the first step produces a Saturday before a Monday holioday?
    You might be interested in [this thread|http://forums.oracle.com/forums/message.jspa?messageID=3350877#3350877]. Among other things, it includes a function for determining if a given date (in any year) is a holiday, without reference to a table.

  • How to get the sample repository data of over 6000 records for products

    Hi,
    I have MDM installed and ready to use with the standard 9 repositories provided by SAP. I was wondering if I can get the unarchive .a2a file with the sample data of records (I think over 6000 records) for the Products repository. I have tried to bring in the two .a2a product files that I have, but it was giving version inconsistent errors. How do and where do I get the real sample data (not the one we can create in data manager) correct version provided by SAP, so that I can get my hands on SAP data manager funtionality.
    Thanks in advance,
    N@v!n K

    Hi Navin,
    Business Content archives that are provided by SAP for MDM do not come with the sample data.
    In the bsuiness content ,if you unzip the file you will see the a2a archive of the rep as provided by SAP and the import /export maps and the lookup data file.
    There is no main records that SAP provide with the sap content it is basically the data modell that SAP provides so that the foundation is set for you and you can now import and work with the data.
    However if you wish to use the demo repository or the training rep from Inquera then you will same some sample data already loaded in MDM rep to work upon.
    Regarding the version problem
    Check the MDM version of the business content rep with the MDM server you are using .They have to match to work correctly.
    You can work with a lower archives of the rep(say SP04) with an Upgraded MDM server (say SP06) by using the Update Repository option in the context menu of the MDM server in Console.
    But the vice versa is not possible.
    Check you MDM server version by clicking on the MDM server and see its details in the right side record detail pane.
    To know more on the demo and Inquera rep kinldy view the below links:
    https://www.sdn.sap.com/irj/sdn/nw-demomodel#section21 (Demo Rep)
    http://www.inquera.com/InqueraCatalog/CustomerLogin.asp(Demo Rep from Inquera you need to register and they will mail you)
    Hope It Helped
    Thanks & Regards
    Simona Pinto

  • HT1766 I Have tried to update to iOS 7 but the iPad has locked on the Terms and Conditions page .I cannot agree to the conditions.Ideas please on how to get the iPad working again.

    having attempted to upgrade to iO7 latest op system,the Ipad has stuck on the Terms & conditions page.It will not accept my agreement to terms and conditions or allow me to read them.
    Ideas please on how to get it to work again,which will have to be via my lap top!
    It sound as if the iPad is woking in the background-i.e.receiving eMails.

    Reset iPad and continue with update.
    Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
    Note: Data will not be affected.

  • How to get the plsql table data into output cursor

    Hi,
    Could anybody please help me.
    Below is an example of the scenario..
    CREATE OR REPLACE PACKAGE chck IS
    PROCEDURE getdata(dept_no IN VARCHAR2,oc_result_cursor OUT sys_REFCURSOR);
    TYPE get_rec is record (ename varchar2(20),
    eno number(12));
    TYPE t_recs IS TABLE OF get_rec INDEX BY BINARY_INTEGER;
    emp_tab t_recs;
    END chck;
    CREATE OR REPLACE PACKAGE BODY chck AS
    PROCEDURE getdata(dept_no IN VARCHAR2,oc_result_cursor OUT sys_REFCURSOR)
    is
    BEGIN
    select ename, eno
    bulk collect into emp_tab
    from emp;
    open oc_result_cursor for select * from table(emp_tab); -- I believe something is wrong here ....
    END;
    END chck;
    the above package is giving me an error:
    LINE/COL ERROR
    10/29 PL/SQL: SQL Statement ignored
    10/43 PL/SQL: ORA-22905: cannot access rows from a non-nested table
    item
    let me know what needs to be changed
    Thanks
    Manju

    manjukn wrote:
    once i get the data into a plsql table, how to get this plsql table data into the cursor?There is no such thing as a PL/SQL table - it is an array.
    It is nothing at all like a table. It cannot be indexed, partitioned, cluster, etc. It does not exist in the SQL engine as an object that can be referenced. It resides in expensive PGA memory and needs to be copied (lock, stock and barrel) to the SQL engine as a bind variable.
    It is an extremely primitive structure - and should never be confused as being just like a table.
    Its use in SQL statements is also an exception to the rule. Sound and valid technical reasons need to justify why one want to push a PL/SQL array to the SQL engine to run SELECT 's against it.

  • How to get the exact day date with the another date field?

    Hi,
    Please help me how to get the specific day of the week's date with the help of another date field.
    Actually , one field(week_day) has 1,2,3,4,5,6,7 here 1--MON,2-- TUE like that.
    another field has the date. based on that date, we have to go to that particular week and need to pick up the date by the above week_day. It should be in that week itself.
    Thanks in advance!!
    Regards,
    Vissu...
    Edited by: vissu on Oct 29, 2010 3:07 AM

    Hi,
    Something like this
    SELECT TRUNC(<DATE_COLUMN>,'DAY')+<WEEK_NO_COLUMN> FROM <YOUR_TABLE>;for the particular week of the date
    SELECT TRUNC(SYSDATE,'DAY')+<WEEK_NO_COLUMN> FROM <YOUR_TABLE>;for the current week
    cheers
    VT

  • CALCULATE THE NEXT WORKING DATE ACCORDING TO THE CALENDAR

    Hello,
    Could somebody tell me the name of any function module or abap class to determine the next working day according to calendar. I need add (let say) 30 days to the date but only working days (I dont take into acount sunday, easter etc.)
    Thanks in Advance
    Adam

    try function BKK_ADD_WORKINGDAY
    or WDKAL_DATE_ADD_FKDAYS
    Cheers
    Thomas

  • How to get the Next free Number for External Number Range

    Hi ,
    To get next free number for External Number Range, I have used NUMBER_GET_NEXT Function module.
    It is throws the exception like  NUMBER_RANGE_NOT_INTERN.
    How can i get the next free number for external number range object. And How to update the Current Number for External Number Range Object
    Scenario.
    Call Function module              NUMBER_GET_NEXT
    Import Parameter.
    NR_RANGE_NR : 02
    OBJECT            : RV_BELEG
    QUANTITY         : 00000000000000000001
    I am getting Exception : NUMBER_RANGE_NOT_INTERN
    Thanks in advance.
    Regards
    Ram

    Hi Anand,
    The SAP system issues the numbers for internal number range intervals automatically. This number is between the from-number and the to-number. The last number issued is logged in the current number level.
    You need to enter a number for external number issue. The number you enter needs to be between the from-number and the to-number. For external number ranges, the number number used is not logged. So the next available number is not possible in a straight forward way.
    Only for Internal number ranges, the FM NUMBER_GET_NEXT can get the next available number.
    Hope this helps.
    Thanks,
    Balaji

  • How to get the next Date

    Hi All,
    I have a date field in which when i enter the date and click on the button I should display the  next day in another inputfield.
    Ex: If i enter 12th Nov 2008 (11/12/2008)i should get 13th Nov 2008 (11/13/2008)
    in the other input field.
    Thank You in Advance.

    Hi,
    Following is the sample code based on todays date
    Date dt = new Date(Calendar.getInstance().getTimeInMillis());
              Calendar calendar = Calendar.getInstance();
              calendar.add(Calendar.DATE, 1);
              System.out.println(calendar.getTime());
    OR
    //Specifically for your sample dates
    Calendar calendar = Calendar.getInstance();
              calendar.set(Calendar.MONTH, 10);
              calendar.set(Calendar.DATE, 12);
              calendar.set(Calendar.YEAR, 2008);
              System.out.println(calendar.getTime());
              calendar.add(Calendar.DATE, 1);
              System.out.println(calendar.getTime());
    Regards
    Ayyapparaj

Maybe you are looking for

  • How can I update my mac os x 10.6.8 to get icloud?

    HOW CAN I UPDATE MY MAC OS X 10.6.8 TO GET ICLOUD?

  • Suggesstions on flat file to IDOC

    Hi,    Help me on following topics,    1) What is the use of port in program RSEINB00. I want this program to read a flat file and convert it into IDOC. How does this program recognize to which IDOC format it has to convert the flat file.    2) what

  • Scenario - Service Tax on Freight

    Hi All, How I can map below scenario - Basic Price - 1000.00 VAT 4 % - 40.00 - Tax code Freight - 100.00 - Condition Type Service Tax on Freight - 25.00 - Not to be inventoried on Material PO Value - 1165.00 Currently we are not adding service tax co

  • DNG conversion fails sporadically with Get Photos From Camera

    Camera: Canon 40D and 5D XP SP2 CS3 Bridge 2.1.1.9 ACR 4.4.1 DNG Converter 4.3.1 Importing my files to Bridge using the Get Photos from Camera (GPFC) option results in sporadic DNG conversion failure. There's no pattern, just a lump of files that don

  • License error launching IDM

    Hi all, I am evaluating the Identity Management Sutie and have installed the whole thing on a single vm image with Oracle 10G as the index db. My goal was to install the demonstration scenario for the Identity Managent. Everything installed fine with