Resetting the number value after a given date.

Hi everyone I was just wondering if this piece of sql will work in resetting the number for days_off to 0 when the date is July 7th. Afterwards I want it to continue doing the SUM of days, just start anew after July 7th (props to Pollywog who gave me the original script which I then butchered and modified, which is why I am asking if it's any good).
WITH t AS (  SELECT id,
                    MAX (strt) strt,
                    MAX (finish) finish,
                    SUM (dys) days_off
               FROM (SELECT id,
                            strt,
                            finish,
                            CASE
                               WHEN TO_CHAR (dy, 'day') LIKE 'saturday%' THEN 0
                               WHEN TO_CHAR (dy, 'day') LIKE 'sunday%' THEN 0
                               ELSE 1
                            END
                               dys
                       FROM vacations
                     MODEL
                        PARTITION BY (ID id)
                        DIMENSION BY (0 d)
                        MEASURES (POCETAK strt, KRAJ finish, POCETAK dy)
                        RULES
                           (dy [FOR d FROM 1 TO finish[0] - strt[0] INCREMENT 1] =
                                 (NVL (dy[CV () - 1], dy[CV ()]) + 1)))
           GROUP BY id
           ORDER BY id)
SELECT t.id,
       t.strt,
       t.finish,
       t.days_off,
       vacations.korisnik,
       SUM (
          CASE
             WHEN SYSDATE != TO_DATE ('01/07/2011', 'dd/mm/yyyy') THEN days_off
             ELSE 0
          END)
       OVER (PARTITION BY vacations.korisnik ORDER BY t.id)
          this_years_running_total
  FROM t, vacations
WHERE t.id = vacations.id

Hi,
sysdate will come with a time factor so you will never reach the equality, you have to change that:
WHEN to_char(SYSDATE,'dd/mm/yyyy') != '01/07/2011' THEN days_offHerald ten Dam
http://htendam.wordpress.com

Similar Messages

  • How to store beyond the range value for a given data type!!!

    Hi all,
    I want to know.Is it possible to create a new data type like int,float in java. which can store any number without any range restrictions.As you know the range of byte data type is -128 - + 127.I don't want any range restrictions.The data type should be able to grow dynamically.
    Regards!!
    Tameshwar Sahu

    The only solution I can think of is to use java objects, Im not sure youll be able to create a new primitive for java !!
    Youd have to put together Integers, posibly in a vector depending on how HUGE a number youd like to create.
    If you reached the max of one, add another to the vector. and then continue with the next.. The problem with this of course is the fact that math operations, will be a bit of a challenge to code. also actuall representation of the value would be a bit tricky as well !! There are however ways to go about this, you just have to think about it a little.

  • Number of days in given date/month

    Hi,
    Can you send query to find the number of days in given date/month
    Regards,
    Venkat.

    If you want No. of days between two date then you can just Subtract them. If you want the number of days in a month you can get the first and last day of the month and subtract them.
    Solution for a month.
    SQL> with t as (select to_date('&month','mmyyyy') as dt from dual)
      2  select (last_day(dt) - trunc(dt, 'mm'))+1
      3    from t
      4  /
    Enter value for month: 012009
    old   1: with t as (select to_date('&month','mmyyyy') as dt from dual)
    new   1: with t as (select to_date('012009','mmyyyy') as dt from dual)
    (LAST_DAY(DT)-TRUNC(DT,'MM'))+1
                                 31
    SQL> /
    Enter value for month: 022009
    old   1: with t as (select to_date('&month','mmyyyy') as dt from dual)
    new   1: with t as (select to_date('022009','mmyyyy') as dt from dual)
    (LAST_DAY(DT)-TRUNC(DT,'MM'))+1
                                 28
    SQL> /
    Enter value for month: 122009
    old   1: with t as (select to_date('&month','mmyyyy') as dt from dual)
    new   1: with t as (select to_date('122009','mmyyyy') as dt from dual)
    (LAST_DAY(DT)-TRUNC(DT,'MM'))+1
                                 31Edited by: Karthick_Arp on Feb 19, 2009 9:56 PM

  • Formula - days before or after a given date = date

    Hi - I'm not great with formulas and have looked through all the help text and still can't find what I need. I am looking for a version of the workday formula that doesn't exclude weekends....so, the function would return a date based on the given number of calendar days before/after a given date. I tried to edit the formula but it produced an error.
    Thanks for your help!

    The Help is not the best tool for newbies.
    The best ones are pointed below.
    If I understand well your question,
    =B2-10
    when B2 contains a valid date may be what you need.
    Yvan KOENIG (VALLAURIS, France) dimanche 7 novembre 2010 18:54:11

  • How Long will it take to reset the 16gb ipad with clear all data in it.

    How Long will it take to reset the 16gb ipad with clear all data in it.

    I have the same problem. I try to reset my ipad / iphone 3g using the reset and delete all content on general. It is almost 2 days now but my ipad / iphone 3g are not yet finish. Only apple logo / looping circle appears on the screen. What will i do? thanks... iOS 5.0.1

  • How can I reset the number authorized Macs in my account?

    How can I reset the number authorized Macs in my account? Two old Macs that I no longer have are still authorized, which leaves me with three working macs at home.

    Hello Joe
    You will find your answer on this page. In summary you have to deauthorize each of the 2 Macs on the Mac thenself. If it's no longer possible, then you have to deauthorize all five Macs and then reauthorize each 3 remaining
    http://support.apple.com/kb/HT1420
    Bye

  • How to validated the number values in Controller

    Hi
    How to validate the number values in Controller.
    Please help me.
    Thanks
    Rajavel Ramalingam

    Hi
    Nagesh Manda,
    MessageTextInput one filed already have varchar2 filed. I am going modified character to number(throw the controller). For the example that page submit button press that time validate the filed. Only enter number. don’t enter charter.
    Thanks
    Rajavel

  • I wanted to know how do you calculate the number of days between two dates

    i wanted to know how do you calculate the number of days between two dates in java ? i get both the dates from the database. i guess there are many issues like leap year and Febuary having diff no of months ..etc.

    thanks..
    I solve my problem as
    public class MyExample {
        public static void main(String a[]) {
            String stdate = "2009-03-01";
            java.sql.Date currentDate = new java.sql.Date(System.currentTimeMillis());
            java.sql.Date preDate = java.sql.Date.valueOf(stdate);
            System.out.println(currentDate);
            System.out.println(preDate);
    //        int dateCom = preDate.compareTo(currentDate);
    //        System.out.println(dateCom);
            long diff = currentDate.getTime() - preDate.getTime();
            int days = (int) Math.floor(diff / (24 * 60 * 60 * 1000));
             System.out.println(days);
    }

  • How to trobleshoot an ipod touch. yesterday i tried to reset the setting then after i click reset it suddenly shut and after a few minutes an apple logo came out. It cannot be open anymore until now. what will i do.please help me thank u

    how to trobleshoot an ipod touch. yesterday i tried to reset the setting then after i click reset it suddenly shut and after a few minutes an apple logo came out. It cannot be open anymore until now and the logo is still their. what will i do.please help me thank u

    Try:
    - iOS: Not responding or does not turn on
    - Also try DFU mode after try recovery mode
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    - If not successful and you can't fully turn the iOS device fully off, let the battery fully drain. After charging for an least an hour try the above again.
    - If still not successful that usually indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.
      Apple Retail Store - Genius Bar              

  • How do I reclaim the unused space after a huge data delete- very urgent

    Hello all,
    How do I reclaim the unused space after a huge data delete?
    alter table "ODB"."BLOB_TABLE" shrink space; This couldn't execute with ora 10662 error. Could you please help

    'Shrink space' has requirements:
    shrink_clause
    The shrink clause lets you manually shrink space in a table, index-organized table or its overflow segment, index, partition, subpartition, LOB segment, materialized view, or materialized view log. This clause is valid only for segments in tablespaces with automatic segment management. By default, Oracle Database compacts the segment, adjusts the high water mark, and releases the recuperated space immediately.
    Compacting the segment requires row movement. Therefore, you must enable row movement for the object you want to shrink before specifying this clause. Further, if your application has any rowid-based triggers, you should disable them before issuing this clause.
    Werner

  • The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.

    The below function is giving me the hours difference what I wanted, but today it is giving us the below error: 
    Msg 535, Level 16, State 0, Line 1
    The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.
    Please Help..
    ALTER FUNCTION [dbo].[GetHoursExcludingWeekdays](@StartDate datetime2,@EndDate datetime2)
    returns decimal(12,3)
    as
    begin
        if datepart(weekday,@StartDate) = 1
            set @StartDate = dateadd(day,datediff(day,0,@StartDate),1)
        if datepart(weekday,@StartDate) = 7
            set @StartDate = dateadd(day,datediff(day,0,@StartDate),2)
        -- if @EndDate happens on the weekend, set to previous Saturday 12AM
        -- to count all of Friday's hours
        if datepart(weekday,@EndDate) = 1
            set @EndDate = dateadd(day,datediff(day,0,@EndDate),-2)
        if datepart(weekday,@EndDate) = 7
            set @EndDate = dateadd(day,datediff(day,0,@EndDate),-1)
        declare @return decimal(12,3)
        set @return = ((datediff(second,@StartDate,@EndDate)/60.0/60.0) - (datediff(week,@StartDate,@EndDate)*48))
        return @return
    end
    ReportingServices

    You'll get this error if the difference between the start and end date is greater that about 68 years due to the "second" DATEDIFF specification.  Perhaps the dates are greater than the expected range due to a data quality issue. 
    Taking the advice from the error message, you could use minutes instead of seconds like the example below the version below.  This could still result in the error of the difference is greater than a couple of hundred years, though.  You might consider
    validating the dates and returning NULL if outside expected limits.
    ALTER FUNCTION [dbo].[GetHoursExcludingWeekdays](@StartDate datetime2,@EndDate datetime2)
    returns decimal(12,3)
    as
    begin
    if datepart(weekday,@StartDate) = 1
    set @StartDate = dateadd(day,datediff(day,0,@StartDate),1)
    if datepart(weekday,@StartDate) = 7
    set @StartDate = dateadd(day,datediff(day,0,@StartDate),2)
    -- if @EndDate happens on the weekend, set to previous Saturday 12AM
    -- to count all of Friday's hours
    if datepart(weekday,@EndDate) = 1
    set @EndDate = dateadd(day,datediff(day,0,@EndDate),-2)
    if datepart(weekday,@EndDate) = 7
    set @EndDate = dateadd(day,datediff(day,0,@EndDate),-1)
    declare @return decimal(12,3)
    set @return = ((datediff(minute,@StartDate,@EndDate)/60.0) - (datediff(week,@StartDate,@EndDate)*48))
    return @return
    end
    GO
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • I set up a iMessage account with iphone number, I sign the number again after auto sign out when Wifi disconnected. Will it also send me a alert message at my iPhone ?

    I set up a iMessage account with iPhone number, I sign in the number again after wifi disconnected. Will it send me the alert message at my iPhone again?

    Did you remove your account information from the other person's iPhone?

  • Mailbox move completes but get "Failed to reset the target mailbox after the move" 481/481

     
    moving a mailbox from exchange 2013 to exchange 2010: it completes but the process tries to reset the target mailbox as a final step about 481 times then gives permanent exception error:
    Failed to reset the target mailbox after the move. Attempt 481/481. Error: SuitabilityDirectoryException
    Target mailbox reset operation was not replicated. Error: TargetMailboxConnectionWasLostPermanentException
    Anand_N

    I have tried moving several different accounts, none of them admin accounts, all getting the same error. I am logged in as domain admin with full rights to exchange. The issue occurs when moving mailboxes from exchange 2013 to exchange 2010.
    1/30/2014 7:24:56 AM [e1] Move has completed and final clean up has started.
    1/30/2014 7:24:57 AM [e1] Source mailbox 'Primary (4bfda0fd-c991-4d40-8f0f-394411ef6848)' was successfully cleaned up after the move.
    1/30/2014 7:24:57 AM [e1] Failed to reset the target mailbox after the move. Attempt 1/481. Error: CouldNotFindDCHavingUmmUpdateTransientException.
    1/30/2014 7:24:57 AM [e1] Post-move cleanup failed. The operation will try again in 30 seconds (1/481).
    1/30/2014 7:25:32 AM [e1] Failed to reset the target mailbox after the move. Attempt 2/481. Error: SuitabilityDirectoryException.
    1/30/2014 7:25:32 AM [e1] Post-move cleanup failed. The operation will try again in 30 seconds (2/481).
    This is four hour wait period. before getting the error :
    Target mailbox reset operation was not replicated. Error: TargetMailboxConnectionWasLostPermanentException
    Anand_N

  • How do I reset the number of activations on Visio 2003 after getting a "too many activations" message?

    I just installed Visio 2003 on a PC, and got the "we can't activate this app via the internet because you've installed it too many times" message. I went back to phone activation, but, of course, that's no longer available for this product.
    How do I get the number of activations reset? Apparently you used to be able to do this by calling Microsoft, but what's the number to call? Or is there another way to do it?
    I'm probably going to need to do it for my copy of Office 2003 also.

    Hi,
    Microsoft has ended support for Office 2003 on April 8, 2014. This change will affect your software updates and security options.
    Please contact your local customer service. Explain to the service (Human being) that you can’t activate Visio 2003 and the error message is “we can't
    activate this app via the internet because you've installed it too many times”.
    You can find
    your local custom support number on the link below.http://support.microsoft.com/gp/customer-service-phone-numbers/en-us
    Hope it can be helpful.

  • Date Picker has to submit the default value after the page load???

    Hello All,
    I have 2 date pickers 'Start' and 'End' on a screen with report that has a where clause using above values. Start defaults to current date, End defaults to current month end date, I have another radio group with default to Monthly......
    Now when the page loads, I see the default values for 'Start' and 'End' date pickers but the report doesn't reflect those values. I added an on change dynamic action, and so when I change the value of 'End' date picker, it submits the page and now the values are reflected in the report........
    I tried creating another dynamic action > with event On Page Load.....and disable fire on page load, and to submit the page, this is causing an infinite loop of submitions........can you please tell me how to achieve this with out putting an exclusive submit button on the Screen.......
    Thanks for your time.
    DK

    user12296343 wrote:
    Hello All,
    I have 2 date pickers 'Start' and 'End' on a screen with report that has a where clause using above values. Start defaults to current date, End defaults to current month end date, I have another radio group with default to Monthly......
    Now when the page loads, I see the default values for 'Start' and 'End' date pickers but the report doesn't reflect those values. I added an on change dynamic action, and so when I change the value of 'End' date picker, it submits the page and now the values are reflected in the report........
    I tried creating another dynamic action > with event On Page Load.....and disable fire on page load, and to submit the page, this is causing an infinite loop of submitions........can you please tell me how to achieve this with out putting an exclusive submit button on the Screen.......
    Thanks for your time.
    You don't have to submit the page here.
    What version of apex?
    What report is it? i.e. Interactive report/Classic report
    Depending on your version of apex you can simply use the Page Items to Submit attribute to set the session state

Maybe you are looking for

  • Sub-Total Issue

    Is there anyway i can update subtotal KZWI6 with a value, becasuse of a configuration mistake in the pricing procedure the system took zero value into the sub-total for certain invoices.

  • No Internet Access after 20 minutes in the router Linksys E2500

    Hi, I have a new Linksys E2500 router. Whenever I try to connect to the internet, it works only for 20 minutes. This problem started 15 days ago. At the first time, the problem was with the Internet Service Company, " Comcast ". After they had fixed

  • Lost garageband 4.1.2

    I had to reinstall one of my MacBook Pro's completely from scratch due to a student getting into some files. Garageband did not reinstall with other applications. I am running 10.5.8. I've tried to download it from the internet but keep getting files

  • Extract metadata from selected files in bridge

    I used to use extensis portfolio to quickly export metadata from selected files to create print worksheets. I could customize which metadata would be displayed. For instance: Thumbnail title pixels file type date created and modified height and width

  • Healing brush and clone stamp tools are not working - Photoshop Elements 11.

    Anyone have suggestions on why the tools stop working?