to calculate the days of sheets each month

Hi all

I need a query which can get leaves from an employee of days each month.

Example:

1.

If an employee has leave of date_start = 15 January 2014 ', date_end = 30 January 2014 "which is in the same month, then it will be"

Duration = 15-30 + 1 = 16 days

Total_days_in_jan = 31 days

Calculation of salary leave will be amount = (: base +: housing) * (: duration) / (Total_days_in_jan)

= (1000 + 2000) * 16/31

' 2. If his two month date_start = 15 January 2014 ', date_end = 10 February 2014.

I wrote code that works perfect below

If to_char(:date_start,'mm') = to_char(:date_end,'mm') then

v_mon_days: = TO_CHAR (last_day (TO_DATE(:date_start,'DD-MON-YYYY')), 'DD');

v_tot: = (nvl(:BASIC1,0) + nvl (:FUJ_LIVING,0)) *(:Duration_)/v_mon_days;

elsif to_char(:date_start,'mm') <>to_char(:date_end,'mm') then

v_mon_days_st_dt: = TO_CHAR (last_day(:date_start), 'DD');

v_mon_days_en_dt: = TO_CHAR (last_day(:date_end), 'DD');

v_lv_days_st_dt: = last_day(:date_start) -: date_start + 1;

v_lv_days_en_dt: =: date_end - trunc(:date_end,'mm') + 1;

v_tot_st_dt: = (nvl(:BASIC1,0) + nvl(:FUJ_LIVING,0)) * (v_lv_days_st_dt) / v_mon_days_st_dt;

v_tot_en_dt: = (nvl(:BASIC1,0) + nvl(:FUJ_LIVING,0)) * (v_lv_days_en_dt) / v_mon_days_en_dt; 

v_tot: = nvl(v_tot_st_dt,0) + nvl(v_tot_en_dt,0);

end if;

Return round (v_tot);

3. If the 3 months off, say date_start = 24-may-2014 date_end = July 2, 2014.

I need some help here... what happens if the 4 month also leave...

Please suggest.

Kind regards

Afzal.

Hi Roger, Etbin

Thanks for your replies.

I found the solution on the month to display between two dates.

To calculate that I used the loop as below

declare

ST DATE: =: date_start;--TO_DATE('24-MAY-2014','DD-MON-YYYY');

ED DATE: =: date_end;--TO_DATE('02-JUL-2014','DD-MON-YYYY');

number of v_t_amount;

CURSOR C1 IS

SELECT more GRAND (ST, ADD_MONTHS (TRUNC (st, 'MONTH'), (LEVEL - 1))) dt.

LESS (ed,

LAST_DAY (ADD_MONTHS (TRUNC (st, 'MONTH'), (LEVEL - 1)))

) ld

OF THE DOUBLE

CONNECT BY LEVEL<>

MONTHS_BETWEEN (TRUNC (ed, 'MONTH'), TRUNC (st, 'MONTH'))

+ 1

ORDER BY 1;

V_AMOUNT NUMBER: = 0;

V_T_AMOUNT NUMBER: = 0;

NUMBER OF V_DAYS;

BEGIN

FOR I IN C1 LOOP

V_AMOUNT: = (nvl(:SALARY_DIFF,0) + nvl(:SPECIAL_ALLOWANCE,0) + nvl(:CF_OTHERS,0)

+ NVL(:Computer,0) + nvl(:PHONE_ALLOW,0) + nvl(:WORK_NATURAL,0)

(+ nvl(:TRANSPORTATION,0) * (i.1d - i.dt + 1) / TO_CHAR (LAST_DAY (i.1d), 'dd'));

V_T_AMOUNT: = V_AMOUNT;

end loop;

end if;

dbms_output.put_line (v_t_amount);

end;

Tags: Database

Similar Questions

  • I need an event to repeat the 1st Thursday of each month; the only option I have is every 8th 6 or each day.

    I wish I had a repetitive on the first event and the third Thursday of each month. I can't make it a monthly event repeated the same day of the week.

    Also, I get an overlay on my Yahoo screen that says I must be disconnected or closed another page and I need to connect when I did this. Is this a problem of Yahoo?

    For your repeat again, I guess that's your Yahoo calendar? This isn't a matter of Firefox, I suggest you try to communicate with yahoo.

    For the other questions, try the following:
    Upgrade to Firefox 15. Then, Firefox Refresh - reset the parameters and modules

  • Find the 2nd Sunday of each month in a report

    Hello

    I have the data of EMP_Name and Join_Date. I have to build a dashboard report where

    1. In the dashboard, there is a command prompt. If I select a year and a month then, the report is expected to show that the data of the respective month.
    2. This report will show the employees who joined the company only after the 2nd Sunday of each month until the end of the month.

    Inputs/suggestions, how to build it?

    Thanks in advance.

    You have a question, Yes... a SQL query... OBIEE do not mean SQL but LSQL, your query will be not really usable like this...

    You're right, it seems that when the first day of the month is a Saturday he jump 1 week...

    The correct formula for the 3rd Friday is:

    TIMESTAMPADD (SQL_TSI_DAY, (14 + 6-CASE WHEN DAYOFWEEK (TIMESTAMPADD (SQL_TSI_DAY, 1-DAYOFMONTH (CURRENT_DATE), CURRENT_DATE)) = 7 THEN 0 END ELSE DAYOFWEEK (TIMESTAMPADD (SQL_TSI_DAY, 1-DAYOFMONTH (CURRENT_DATE), CURRENT_DATE))), TIMESTAMPADD (SQL_TSI_DAY, 1-DAYOFMONTH (CURRENT_DATE), CURRENT_DATE))

    If instead of CURRENT_DATE you want to use your own column date just to replace in the formula and it works.

  • How to find the first Sunday and the second Saturday of each month

    Hi all

    How to find the first Sunday and the second Saturday of each month

    Thank you

    Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production

    994122 wrote:

    Hello

    I need to pass the months parameter how to do this? like Jan, Feb etc... (one of those)

    Do you have a procedure?

    Should you output only for the months you passed in the parameter?

    The easiest way is to set the parameter as date. When you go such as p_date as DATE ' 2014-10-01', then you can

    PROCEDURE two_dates)

    p_date IN DATE

    p_first_sunday DATE

    p_second_saturday DATE

    )

    IS

    BEGIN

    p_first_sunday: = NEXT_DAY (TRUNC (p_date, 'MM') - 1, TO_CHAR (DATE ' 2014-10-12', 'DAY'));

    p_second_saturday: = NEXT_DAY (TRUNC (p_date, 'MM') - 1, TO_CHAR (DATE ' 2014-10-11', 'DAY')) + 7;

    END two_dates;

    Or you describe what you need.

  • How to get the second Monday of each month in a given date range?

    In Oracle forms, how to get the second Monday of each month in a given date range?

    I tried below using the query WITH the Clause, but it seems that WITH Clause does not work in Oracle forms. So is there another way to do this in Oracle forms?

    WITH month_range AS

    (

    SELECT TO_DATE ('Dec 2013', 'Mon YYYY') AS first_month

    , TO_DATE ('Mar 2014', 'Mon YYYY') AS last_month

    OF the double

    )

    SELECT NEXT_DAY (6 + ADD_MONTHS (first_month

    , LEVEL - 1

    )

    , 'MONDAY '.

    ) AS second_monday

    OF month_range

    CONNECTION OF LEVEL < = 1 + MONTHS_BETWEEN (last_month, first_month)

    ;

    Thanks in advance.

    Good fishing, when the first day of the month is Thursday... So I changed the query accordingly... Try the below

    SELECT CASE WHEN TO_CHAR (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'DY') = 'game '.

    THEN NEXT_DAY (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'THU')

    Of OTHER NEXT_DAY (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'Game') + 7

    END AS second_day

    FROM (SELECT SYSDATE startdate,

    SYSDATE + 300 enddate

    THE DOUBLE)

    CONNECT BY LEVEL<=>

  • How to get the date for the first Monday of each month

    Dear members,

    How to get the date for the first Monday of each month.

    I wrote the following code

    SELECT decode (to_char (trunc (sysdate + 30, 'MM'), 'DAY'), 'MONDAY', trunc (sysdate + 30, 'MM'), NEXT_DAY (trunc (sysdate + 30, 'MM'), "LUN")) FROM DUAL

    But he looks at complex bith.

    Abhishek

    Published by: 9999999 on 8 March 2013 04:30

    Use the IW format - it will make independent NLS solution. And all you need is truncated 7th day of each month using IW:

    select  sysdate current_date,
            trunc(trunc(sysdate,'mm') + 6,'iw') first_monday_the_month
      from  dual
    /
    
    CURRENT_D FIRST_MON
    --------- ---------
    08-MAR-13 04-MAR-13
    
    SQL> 
    

    Here is the list of the first Monday of the month of this year:

    with t as(
              select  add_months(date '2013-1-1',level-1) dt
                from  dual
                connect by level <= 12
             )
    select  dt first_of_the_month,
            trunc(dt + 6,'iw') first_monday_the_month
      from  t
    /
    
    FIRST_OF_ FIRST_MON
    --------- ---------
    01-JAN-13 07-JAN-13
    01-FEB-13 04-FEB-13
    01-MAR-13 04-MAR-13
    01-APR-13 01-APR-13
    01-MAY-13 06-MAY-13
    01-JUN-13 03-JUN-13
    01-JUL-13 01-JUL-13
    01-AUG-13 05-AUG-13
    01-SEP-13 02-SEP-13
    01-OCT-13 07-OCT-13
    01-NOV-13 04-NOV-13
    
    FIRST_OF_ FIRST_MON
    --------- ---------
    01-DEC-13 02-DEC-13
    
    12 rows selected.
    
    SQL> 
    

    SY.

  • Calculate the days of salary

    Dear friend


    I want to calculate the days of salary. We pay the salaries of the 21st of the month last to the 20th of the current month.

    I want to create a view where it will show of the the Scriptures based on this month wise condition

    Select empno, name, daytype, count (empno) days, MAX (TO_CHAR (ADATE, 'MONTH')) in dailyattendence
    When al > =('20-OCT-2010') AND ADATE < =('20-NOV-2010')
    Group by empno, daytype
    order by empno


    for ex

    562 SEUN BÉLANGER AFTERNOON OCTOBER 1
    562 SEUN BÉLANGER MORNING OCTOBER 2
    562 SEUN BÉLANGER NIGHT OCTOBER 2
    562 SEUN OFF BÉLANGER 1 OCTOBER

    562 SEUN BÉLANGER AFTERNOON NOVEMBER 1
    562 SEUN BÉLANGER MORNING 2 NOVEMBER
    562 SEUN BÉLANGER NIGHT NOVEMBER 2
    562 SEUN OFF BÉLANGER 1 NOVEMBER

    Suggest me how to set the dates so that I can get the report as shown above,

    Sandy

    It doesn't really have anything to do with the forms, but here's a solution.
    To get the 21st of the month before you use:

    select to_date('21'||to_char(add_months(sysdate,-1),'mmyyyy'),'ddmmyyyy')
    from dual;
    
    TO_DATE('
    ---------
    21-OCT-10
    

    The same for the 20th of this month. So you get:

    where adate between to_date('21'||to_char(add_months(sysdate,-1),'mmyyyy'),'ddmmyyyy')
       and to_date('20'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
    

    An addition: If your date includes a time, you must use the use trunc (date).

    Published by: InoL on November 11, 2010 12:10

  • Select the last record of each month

    Hello

    to select the last docnumber and qty of every month

    Structure

    Name Null?    Type

    ------------------------------- -------- ----

    PRODUCTCODE NUMBER

    NUMBER NUMBER

    DATE OF PLANFORMONTH

    NUMBER OF CLEXPECTEDQTY

    NUMBER OF CLCONFIRMQTY

    NUMBER OF CLFGBUFFERQTY

    NUMBER OF CLTOTPRINTBUFFER

    in this select query if I take the sum he required all records where, as I want the last record of each month

    SELECT productcode docnumber MAX (Number), planformonth, SUM (clexpectedqty) clexpectedqty (planformonth) MAX.

    SUM (clconfirmqty) clconfirmqty, SUM (clfgbufferqty) clfgbufferqty, cltotprintbuffer OF FGSALESPLAN of the SUM (cltotprintbuffer)

    GROUP BY productcode, (planformonth)

    Sandy

    Hello

    Thanks its working now the code is written as below:

    SELECT * FROM

    (SELECT

    e.*,

    ROW_NUMBER() OVER (partition by PRODUCTCODE by DOCNUMBER DESC order) r

    Of

    E FGSALESPLAN)

    WHERE r = 1 AND

    entryvalid = 'Y '.

    order by Number

    Sandy

  • the 50 GB renews each month

    The upgrade to 50 GB renews each month. Or you can use the 50 GB as long as you need and cancel the upgrade after the month.

    iCloud storage upgrades are charged every month, unless cancellation or a problem with the payment.

    (143463)

  • Function to calculate the days of work

    Hi all

    I accidentally develop an application in which I had to follow the thread below and it works perfectly for the weekend (Saturday and Sunday)

    PL/SQL function to calculate the non-working days

    Now, my specific question is: how to implement the same function , but weekends (Fri & sat).

    I tried to recognize the logic behind the calendar to change the days of the weekend, but I suspect.

    I need your recommendation around this function specifically.

    !-[CodeBlockStart:3cad70b5 - 81 a 0-4f6b-909 a-cacb29e25953]--> BOX WHEN IN l_case (-"Mon6", "Tue5", "Wed4", "Thu3", "Fri2" - exclude Saturday & Sunday, workday begins from Monday 'Sun6', 'Mon5', 'Tue4', 'Wed3', 'Thu2' - remove begins day 2 business days (Fri & sat) on Sunday and maintaining the order of the sequences,-"Sat1", "Sun1", "Sun2', 'Sun3', 'Sun4' - Include weekend can be for the rest of the week) , "Sat1", "Sat2", 'Fri1', "Sat3", "Sat4" - includes my week ends replace (with FRI Sat) & (Sun to SAT) & law enforcement-sequence, "Sun5', 'Sun6',"Sat5","Sat6"- replace (Sun with Sam).                                                                   ) 1 THEN WHEN IN l_case (-'Tue6', 'Wed5', 'Wed6', 'Thu4', "Thu5" - Old (Saturday and Sunday) end over the next week - I guess - sequence of days - since the week days sequence Changed (number 1 or 1 step backward) when numbers also changed accordingly "Tue5", "Wed4", "Wed5", "Thu3", "Thu4" - ok-, 'Thu6', 'Fri3', "Fri4", "Fri5", "Fri6", "Thu5", "Sun1", "Sun2", 'Sun3', 'Sun4' - contiue to Thu sequence number & then replace my current (Friday) holiday with start of work dat (Sun) "Fri1") (, 'Fri2', 'Fri3', 'Fri4', "Fri5") THEN 2 0 OTHERWISE END;

    Thanks in advance.

    Amatu Allah

    with

    calendar as

    (select dat_val,

    cases where to_char(dat_val,'mm-dd') in (12-25', 12-26', ' 01-01')-in fact select the host table to_char(holiday_date,'mm-dd')

    then "vacation."

    When to_char (dat_val, 'Dy') in ('Friday', 'Saturday')

    then 'weekend '.

    else 'work '.

    end dat_type

    sum (case when to_char(dat_val,'mm-dd') in (12-25', 12-26', ' 01-01'))

    then 0

    When to_char (dat_val, 'Dy') in ('Friday', 'Saturday')

    then 0

    1 other

    end

    ) on working_count (dat_val control)

    from (select date "' 2015-12-01 + level - 1 dat_val)

    of the double

    connect by level<=>

    )

    )

    Select dat_val,

    dat_type,

    working_count

    calendar

    where dat_val between to_date(:lo_date,'yyyymmdd') and to_date(:hi_date,'yyyymmdd')

    and dat_type! = work «»

    DAT_VAL DAT_TYPE WORKING_COUNT
    11/12/2015 end of week 8
    12/12/2015 end of week 8
    18/12/2015 end of week 13
    19/12/2015 end of week 13
    25/12/2015 holiday 18
    26/12/2015 holiday 18
    01/01/2016 holiday 23
    02/01/2016 end of week 23
    08/01/2016 end of week 28
    09/01/2016 end of week 28

    Select to_date(:lo_date,'yyyymmdd') lo_date,

    to_date(:hi_date,'yyyymmdd') hi_date,

    dat_val,

    dat_type,

    working_count,

    Lead (working_count) more (order of dat_val) - working_count + 1 working_days,

    to_date(:hi_date,'yyyymmdd') - to_date(:lo_date,'yyyymmdd') - lead (working_count) (order dat_val) + working_count non_working_days

    calendar

    where dat_val in (to_date (:hi_date,'yyyymmdd'),to_date(:lo_date,'yyyymmdd'))

    LO_DATE HI_DATE DAT_VAL DAT_TYPE WORKING_COUNT WORKING_DAYS NON_WORKING_DAYS
    10/12/2015 10/01/2016 10/12/2015 work 8 22 10
    10/12/2015 10/01/2016 10/01/2016 work 29 - -

    Concerning

    Etbin

  • How to show the extent of the day and date a month before her?

    Experts,

    I have a list of dates and measures. If I select a date from the calendar (as a command prompt) prompt, there bring it records of this date and the date of the month previous (reduce the 30 days of the date of the day). I have no idea on how to proceed with this requirement. Any help is appreciated.

    I'm using OBIEE 11 g.

    Kind regards
    LIBERATOR

    Manon says:
    Experts,

    I have a list of dates and measures. If I select a date from the calendar (as a command prompt) prompt, there bring it records of this date and the date of the month previous (reduce the 30 days of the date of the day). I have no idea on how to proceed with this requirement. Any help is appreciated.

    I'm using OBIEE 11 g.

    Kind regards
    LIBERATOR

    If you are looking for two dates, the date of the command prompt and a "30 days prior", then follow these steps:

    (1) create a dashboard on the date column and assign a TICKET called pv_Date.

    (2) in your report, put a filter on the same date column:

    table. "Date = ' @{pv_Date}"

    OR
    table.date = TIMESTAMPADD (SQL_TSI_DAY-30, TIMESTAMP ' @{pv_Date} "")

    If you wanted to say: 'all values up to 30 days before the maximum value of the line,' enter the following:

    table.date BETWEEN <= '@{pv_date}'="" and="" table.date="">= TIMESTAMPADD (SQL_TSI_DAY-30, TIMESTAMP ' @{pv_Date} "")

  • calculate the day of the year using the date.

    Hi all
    Can calculate us the day of the year using the date form? Is this possible? Please help me thanks in advance
    Like this
    30/08/2009-30/08/2010 after calculation - 365


    Sarah

    Published by: SarahSarahSarah on August 30, 2009 12:49 AM

    Sarah.

    : ins1.noday must be a part of number!

    Create a function in forms like this:

    function get_nodays ( f_dtm_start in date,
                          f_dtm_end   in date ) return number is
    begin
    if
      f_dtm_start is null OR
      f_dtm_end is null
    then
      return ( null );
    end if;
    return ( trunc ( f_dtm_start ) - trunc ( f_dtm_end ) );
    exception when others
    then message ( sqlerrm || ' in function get_nodays occured.' );
    return ( null );
    end;
    

    Call this function in the when-validate-point triggers on ins1. INSPERIOD and: ins1.end love

    :ins1.noday := get_nodays ( :ins1.INSPERIOD, :ins1.end );
    

    It is redundant to have the: noday as a cause of part of database
    the value may by calculated every time using the values INSPERIOD and: end.

  • How can I program a list of Interfaces that will run on the last Sunday of each month...

    Hi can someone help me to achieve this scenario...

    Thanks in advance...

    Hello

    Make the scenario for each interface and expand when the script option is planning.

    Scheduling---> option execution---> select month (day of week)---> monthly date = last & Sunday and schedule accordingly.

    Let me know

    Thank you

  • calculate the days remaining until a given date

    Hello

    I am facing a problem and can not find a good solution.

    I want to calculate how many days there are still up to a certain date.

    It is because I want to build in a callback to the re-kalibrate hardware which is used every year.

    So if it's today 05/11/2012, and the constant is 21/05/2012 labview must calculate there are still 10 days left before the re-kalibration must be finished.

    Someone has any idea how to do this?

    Thanks in advantage!

    of course, don't forget that time stamps are DBL in seconds.

    Hope this helps

  • Nomination for the third Wednesday of each month

    How can I set up my monthly calendar to an event that occurs every third Wednesday of the month?  Thank you.

    Hello

    • You use windows calendar or any other program?

    If sa is the Windows Calendar, then it is not possible to do.

    http://Windows.Microsoft.com/en-us/Windows-Vista/customize-Windows-Calendar

    Diana

    Microsoft Answers Support Engineer

Maybe you are looking for