[8i] Need help updating/fixing a workday table

I'm working in an old database:
Oracle8i Enterprise Edition Release 8.1.7.2.0 - Production
PL/SQL Release 8.1.7.2.0 - Production
CORE 8.1.7.0.0 Production
TNS for HPUX: Version 8.1.7.2.0 - Production
NLSRTL Version 3.4.1.0.0 - Production
I'm trying to fix a workday calendar, and I'm not exactly sure how to do it. I'm used to querying data, not making changes to the data...
Here's some sample data:
CREATE TABLE     test_cal
(     clndr_dt     DATE     NOT NULL
,     work_day     NUMBER(3)
,     clndr_days     NUMBER(6)
,     work_days     NUMBER(5)
INSERT INTO     test_cal
VALUES     (TO_DATE('12/30/2010','mm/dd/yyyy'), 254, 11322, 7885);
INSERT INTO     test_cal
VALUES     (TO_DATE('12/31/2010','mm/dd/yyyy'), 255, 11323, 7886);
INSERT INTO     test_cal
VALUES     (TO_DATE('01/01/2011','mm/dd/yyyy'), 0, NULL, NULL);
INSERT INTO     test_cal
VALUES     (TO_DATE('01/02/2011','mm/dd/yyyy'), 0, NULL, NULL);
INSERT INTO     test_cal
VALUES     (TO_DATE('01/03/2011','mm/dd/yyyy'), 1, NULL, NULL);
INSERT INTO     test_cal
VALUES     (TO_DATE('01/04/2011','mm/dd/yyyy'), 2, NULL, NULL);
INSERT INTO     test_cal
VALUES     (TO_DATE('01/05/2011','mm/dd/yyyy'), 3, NULL, NULL);
INSERT INTO     test_cal
VALUES     (TO_DATE('01/06/2011','mm/dd/yyyy'), 4, NULL, NULL);
INSERT INTO     test_cal
VALUES     (TO_DATE('01/07/2011','mm/dd/yyyy'), 5, NULL, NULL);
INSERT INTO     test_cal
VALUES     (TO_DATE('01/08/2011','mm/dd/yyyy'), 0, NULL, NULL);
INSERT INTO     test_cal
VALUES     (TO_DATE('01/09/2011','mm/dd/yyyy'), 0, 11332, 7895);
INSERT INTO     test_cal
VALUES     (TO_DATE('01/10/2011','mm/dd/yyyy'), 6, 11333, 7896);Note: 12/31/2010 is the last time I am 100% sure the data in the table is good. After that, clndr_days and work_days are either missing or, at least in the case of work_days, are not correct.
This is a two-part question, since I need to fix both clndr_days and work_days. (You can probably fix them both with one statement, but I broke it into two to start, to simplify it for myself).
I only show 12 days in my sample data, but really, the table stretches back a number of years, and forward another 5 or so years.
PART 1: fixing clndr_days
I put together this query:
SELECT     clndr_dt
,     work_day
,     work_days
,     clndr_days
,     min_clndr_day + r_num     AS clndr_days_test
FROM     (
     SELECT     t.*
     ,     MIN(clndr_days)     OVER(ORDER BY clndr_dt)     AS min_clndr_day
     ,     ROW_NUMBER() OVER(ORDER BY clndr_dt)-1     AS r_num
     FROM     test_cal t
     WHERE     clndr_dt     >= TO_DATE('12/31/2010','mm/dd/yyyy')
;Which gives the right clndr_days (as clndr_days_test), but I'm not sure how to get that into the table.
This doesn't work:
UPDATE     test_cal
SET     clndr_days     =     (
                    SELECT     min_clndr_day + r_num
                    FROM     (
                         SELECT     t.*
                         ,     MIN(clndr_days)     OVER(ORDER BY clndr_dt)     AS min_clndr_day
                         ,     ROW_NUMBER() OVER(ORDER BY clndr_dt)-1     AS r_num
                         FROM     test_cal t
                         WHERE     clndr_dt     >= TO_DATE('12/31/2010','mm/dd/yyyy')
                         ) c
                    WHERE     c.clndr_dt     = ???  -- how do I make this equal whatever the clndr_dt is for the record I'm updating?
WHERE     clndr_dt     >      TO_DATE('12/31/2010','mm/dd/yyyy')and I'm not sure how to make it work...
PART 2: Fixing work_days
Then, I can't seem to put together a query for work_days.
This is what I have so far, but it doesn't work quite right, and then it also needs to be an UPDATE statement as well:
SELECT     clndr_dt
,     work_day
,     work_days
,     clndr_days
,     min_work_day + r_num     AS work_days_test --this isn't right, when work_day is 0 work_days_test should be the previous work_day not the minimum work_day
FROM     (
     SELECT     t.*
     ,     MIN(work_days)     OVER ( ORDER BY clndr_dt)     AS min_work_day
     ,     CASE
               WHEN     work_day     <> 0
               THEN     ROW_NUMBER()     OVER ( PARTITION BY     CASE
                                                  WHEN     work_day <> 0
                                                  THEN     1
                                                  ELSE     2
                                             END
                                     ORDER BY     clndr_dt
               ELSE     0
          END               AS r_num
     FROM     test_cal t
     WHERE     clndr_dt     >= TO_DATE('12/31/2010','mm/dd/yyyy')
;(When I tried using LAG, that didn't work either, because you can have more than 1 non-work day in a row, and so it only works for the first non-work day to have the correct work_days, and then it's back to being wrong again)
This is what I want my table to look like in the end:
CLNDR_DT                   WORK_DAY       WORK_DAYS CLNDR_DAYS_TEST
12-31-2010 00:00:00         255.000       7,886.000    11,323.000
01-01-2011 00:00:00            .000       7,886.000    11,324.000
01-02-2011 00:00:00            .000       7,886.000    11,325.000
01-03-2011 00:00:00           1.000       7,887.000    11,326.000
01-04-2011 00:00:00           2.000       7,888.000    11,327.000
01-05-2011 00:00:00           3.000       7,889.000    11,328.000
01-06-2011 00:00:00           4.000       7,890.000    11,329.000
01-07-2011 00:00:00           5.000       7,891.000    11,330.000
01-08-2011 00:00:00            .000       7,891.000    11,331.000
01-09-2011 00:00:00            .000       7,891.000    11,332.000
01-10-2011 00:00:00           6.000       7,892.000    11,333.000(sorry about all the extra decimal places)
Edited by: user11033437 on Jan 11, 2012 1:40 PM

Hi,
Thanks for posting the CREATE TABLE and INSERT statements, the very clear desired output, and your attempts; that's all very helpful. It would also be helpful to explain how you get the results you want from the sample data. There's always a chance someone might coincidentally get the right results for the wrong reasons with the small set of sample data, but would cause you to get wrong results with your full data.
It looks like clndr_days is the total number of days since some conventional starting point (maybe when the company started), and that work_days is the total number of work days from some starting point. It looks like work_day is 0 when the day is not a working day, and otherwise, it's the total number of working days so far in the calendar year. Is that right?
You said the data after December 31, 2010 isn't reliable. Did you mean that two columns (clndr_days and work_days) are unreliable, but the rest of the data is reliable? That is, are you sure there is exactly one row per day even after 2010, and that the work_day column is accurate? If so, you can do this:
UPDATE       test_cal     m
SET       (clndr_days, work_days) =
     SELECT     MIN (clndr_days) + COUNT (*) - 1          -- clndr_days
     ,     MIN (work_days)  + COUNT ( CASE
                                           WHEN  work_day > 0
                                AND   clndr_dt > TO_DATE ('12/31/2010', 'MM/DD/YYYY')
                                THEN  1
                            END
                             )               -- work_days
     FROM     test_cal
     WHERE     clndr_dt     BETWEEN     TO_DATE ('12/31/2010', 'MM/DD/YYYY')
                    AND     m.clndr_dt
WHERE     clndr_dt     > TO_DATE ('12/31/2010', 'MM/DD/YYYY')
;You were right: it is possible to set both columns at the same time.
It's a shame that you're using Oracle 8.1. The MERGE command, which was new in Oracle 9.1, is a lot clearer and more efficient. If you could use MERGE, you could basically use the code you posted as the core of a MERGE statement.
The UPDATE statement above assumes that, for the inaccurate days, clndr_days and work_days will never be lower than the last accurate value. If that's not the case, the solution is a little more complicated. You could avoid that problem, and make the statment faster as well, by simply hard-coding the last accurate values of clndr_days and work_days in the UPDATE statment, where I used MIN. (This sounds like one situation where efficientcy isn't a big deal, however. You'll probably never do this exact UPDATE statement again, so whether it runs in 1 second or 10 minutes might not matter much.)
Sorry, I don't have an Oracle 8 database to test this. It works in Oracle 9.2, and I don't believe it uses any features that aren't available in 8.1.

Similar Messages

  • TS1646 I'v tried many times to update my applications however, my account can't do it because security code for my card is incorrect note that I'm sure my card details are correct completely so i need help to fix it as much as you can plz. Thnks

    Hi
    I'v tried many times to update my applications however, my account can't do it because security code for my card is incorrect note that I'm sure my card details are correct completely so i need help to fix it as much as you can plz. Thnks

    Look, I understand I still need a card attached to the account. The problem is, it won't accept my card because I only have 87 cents in my bank account right now.
    If I had known there would be so much trouble with the iTunes card, I would have just put the cash in my bank account in the morning instead of buying an iTunes card (I didn't expect the banks to be open on Thanksgiving of course).
    Apple will only accept cards that have a balance. The balance is so small in my account that it won't accept it as a valid card.
    I'm going to have to contact Apple anyway to reset the security questions. That's obvious. Your answers were not exactly helpful. You didn't tell me anything I don't already know, but thanks for trying to be helpful.

  • I need help in Fixing my Hp Split x2

    I need help in fixing my hp split x2. I got it with windows 8 but i upgraded to Windows 8.1. sine then I stop accessing my D:/ drive ( 500gb HDD)on which I stored data. Besides, I get DCP watchdog violation Error each time I disconnect the tablet and reconnet it. I also get another error message: DCP_DRIVER_POWER_STATE_FAILURE. Can somebody help me out?

    Hi Alsaab73,
    Thank you for visiting the HP Support Forums and Welcome. I have read your thread on your and getting an error message. The HDD that are you using, I would need the model number. Have you looked in the device manager to see if there is a conflict with the driver installed? It might be listed under the USB devices? Have you tried a different port on the Notebook?  Right clicking an updating the driver might be all that is needed.
    As per the description of the issue you get error DPC_WATCHDOG_VIOLATION.
    Is the issue confined to any particular game or a certain function you are choosing on the Notebook?
    The First thing you need to try is disable any firewalls or virus protection and restart the Notebook.
    If that does not helps try these steps from Microsoft.
    Boot the computer using the Windows 8 bootable DVD.
    On the Install Now screen click on Repair your computer.
    You will then see a blue screen and an option to choose.
    Click on Advanced Options and then click on Troubleshoot.
    Click on Automatic Repair and follow the prompted instructions.
    Hope this helps.
    Thanks.
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos, Thumbs Up" on the bottom to say “Thanks” for helping!

  • When ever i try to download my iPod recovery software, it keeps saying connection timed out. really annoyed and need help to fix it

    when ever i try to download my iPod recovery software, it keeps saying connection timed out. really annoyed and need help to fix it

    - Next try the manual install method of:
    iDevice Troubleshooting 101 :: iPhone, iPad, iPod touch
    If the iPod was Disabled, place the iPod in recovery mode after the firmware download is complete and then restore using the instructions in the article. Sometimes recovery mode timeouts and returns to disabled before the firmware download is complete.
    - Then try on another computer

  • HT1267 i need help updating without wifi hook up. I was told I could do through my "itunes"

    I need help updating without wifi hook up. I was told I could do it through my "itunes"

    after selecting restore from backup, you should see a screen asking you wich backup (on the computer)

  • HT1338 need help updating to snow leopard

    need help updating to snow leopard

    Hi Billy,
    First you need to research all the problems people are having with the higher OSX versions, & make sure you have a bootable clone of what you have just in case.
    then you must get 10.6 if they still have it, install it & update to 10.6.8 so you have the App Store to buy & download the huge 10.8 Installer.
    Snow Leopard/10.6.x Requirements...
    General requirements
       * Mac computer with an Intel processor
        * 1GB of memory (I say 4GB at least, more if you can afford it)
        * 5GB of available disk space (I say 30GB at least)
        * DVD drive for installation
        * Some features require a compatible Internet service provider; fees may apply.
        * Some features require Apple’s MobileMe service; fees and terms apply.
    Which apps work with Mac OS X 10.6?...
    http://snowleopard.wikidot.com/
    It's been pulled from the online store & Apple Stores, so you have to call Apple to buy it, last I heard.
    Call Apple Sales...in the US: 1-800-MY-APPLE. Or Support... 1-800-275-2273
    Other countries...
    http://support.apple.com/kb/HE57

  • Need help to fix my computer, dude: crashes

    I am Manoj. I am from India. There is a problem with my desktop computer. Now days, it gets hanged on regular basis due to which I am unable to work with it. Sometimes it hangs 10-12 times a day. I need help  to fix my computer, dude. One more thing sometimes when it hangs, there are many horizontal lines on the monitor and I hear a sound of beep from the CPU.Please help me.
    Thanks.

    Hello manojyd,
    The problem is it could be a huge list of things that is causing the issue.
    Let's start by stress testing the system and seeing if it gets too hot.
    How to Stress Test your Hardware for Stability and Heat Problems with Prime95
    If I have helped you in any way click the Kudos button to say Thanks.
    The community works together, click Accept as Solution on the post that solves your issue for other members of the community to benefit from the solution.
    - Friendship is magical.

  • HT4623 I need help updated my iphone, please help

    My need help updating my iphone, I went through the steps to update and now it shows connect to itunes, what do I need to do next.?

    Rajan Gupta wrote:
    ...it is continuously showing an error.
    See here  >  http://support.apple.com/kb/TS3424
    Also see this discussion.
    https://discussions.apple.com/message/21189708

  • HT1206 I can't log into the Itunes store.  I type in my Apple ID and my password and the message "This Apple ID cannot be used for the iTunes Store." "Enter another Apple ID."  I need help on fixing this.

    I can't log into the Itunes store.  I type in my Apple ID and my password and the message "This Apple ID cannot be used for the iTunes Store." "Enter another Apple ID."  I need help on fixing this.

    Yeah I'm starting to see a ton of forums posts right now about the same thing :/ I wonder what's going on

  • I have Iconia Tab A500, running 3.0, need help updating using microsd card, got Acer update download

    I have Iconia Tab A500 running 3.0, need help updating, I downloaded all updaes list in the acer supprt, all versions, 3.0, 3.1, 3.2, and 4.something, I read on the acer support somewhere I can use a microsd card to update my device, because acer no longer provides automatically, when i try it says "poor network connection, move to anthoer location.", Do I need to update all the listed updates, or can i only update, using the 4. 0? to get the last known update. I also downloaded, "Documents, Apllications, Drivers, Patches, and O.S..... How do i intsall all these updates, I think am running the very lowest version available, Please Help me... Thank you in advance.

    the update listed on the acer website, that mentions the a500 update is 'kernal source code (for Android 4.0 Ice Cream Sandwich) it's 96.7MB's released 2012/05/08' is that the right one i need? There is also a list of 3 O.S updates, released in 2014/09/05, 391.5MB's, 394.3MB's, and 391.5MB's large, what are those updates, I clicked the model and followed the directions that the acer website asks, and i ended with a list of update released in 2014/09/05, and a Document update released in 2014/12/17, 112.7KB's large,  list of updates reased in 2014/.... and in the Android 4.0 culumn, there is an update that says O.S update released in 2014/09/05, 434.2MB's large, and a Patch Update, that was released in 2013/03/21, what are these updates? listedin the aver website... http://www.acer.ca/ac/en/CA/content/drivers 

  • IMac froze after accidentally dropping hundreds of jpegs in desktop.......need help to fix.....desktop filled now..thanks

    iMac froze after accidentally dropping hundreds of jpegs in desktop.......need help to fix.....desktop filled now..thanks

    Important: mende's suggestion will remove everything from your Desktop, not just the jpegs. Not good. Do the following instead. Open Terminal in Utilities and copy/paste, then hit return after each. The second will create a folder on the Desktop called "photos." The third command will move all of them into that new  folder, "photos" This will save them. These commands assume you are logged into the account with the troubled Desktop.
    cd ~/Desktop
    mkdir photos
    mv *.jpg photos/
    If you don't care about saving them then the following will delete them. (It is critical that you only use copy/paste.)
    cd ~/Desktop
    rm *.jpg
    Message was edited by: WZZZ

  • I get error 0x80073cf9 now and I need help to FIX Windows Store can't update any Apps & can't install any Apps now?

    Hi I hope some one can tell me step by step how to fix windows 8.1, I can't update any of my Apps and can't install any new apps now and I get error code 0x80073cf9?  But my problem is different than most of the other FIXES I read about, because nothing
    fixes my problem to be able to install new Apps and get app updates and stop getting that error code?
    I keep getting same error code 0x80073cf9 after I try any of the FIXES I have read about and tried all  the fixes on  my Lenovo Z580 laptop, that came with windows 8 and updated to 8.1.  And ever since I bought this laptop I could
    always install and update all my apps for the last year when I had Win 8 and Win 8.1 now.   This has been going on since April and May and its driving me crazy!    And from the May updates I did get all the updates and
    I also installed the KB update  that said I need this KB to get all updates in the future.  
    But all the other people when they get this error code they could not even open and use any of their Apps already installed.  And they also get the error code when they try to update or get a new apps.   
    But I can click on any APP installed already and use all my Apps with no problems.     I have read so many how to fix this error code but nothing works! :-(      I have tried a lot of 
    the fixes on Microsoft forums that says do this and the fix will get rid of the error code but I keep getting the same error code after I try that  fixes.    And I have read a lot of other windows 8 an windows 8.1  web sites when
    I search for how to fix this error code?   And tried all of the fixes that were different from the Microsoft forum fixes. But after I try those fixes I still can't install any apps or can't get my app updates? 
    Please to any person's who can help me by giving me  more that 1 fix, because I have tried so many fixes, If you know more that 1 fix tell me how to do your fix step by step so I can understand what you say to do to fix my windows store? 
    Thanks for any and all help?  And if I don't get any help in this section of the forum I will try to put this in a different area, if I don't get any help at this section of the forum I will try to ask this in another part of he forum ok?   
    I really need HELP with this so I can get my laptop working again to install new apps and get the updates to my apps? 

    Fixed the problem by going to settings/store and logging out with apple ID.  Then logged back in with password and updates, apps, and iTunes store seem to work ok now.

  • Just installed security update 2014-002, now Itunes will not open. Have rstrated but no change, need help to fix, please

    Just installed security update 2014-002, now Itunes will not open, I have rebooted twice with no effect, I don't know what else to do to get my itunes back. Need help please

    Believe I've firxed my problem, at least, ITunes is now working again. I followed the information provided from a couple of posts on this thread, (1) re restarting with command-s held down; did it twice, made no differerence; (2) manually re-installed the Security update; no difference; each time restarting, no effect; (3) shutdown the computer; I did for 35 minutes, upon restart, ITunes is back to normal, seems to be working fine. Turning the computer off must clear the cache?

  • Need help Updating Records in a Report Region

    We have created some javascript to check a drop down used in a report region.
    This is the way the report is supposed to work:
    The first time the user comes to this screen he will go down the list and select a value of '1' or '2' for col2.
    When col2 drop down has a value of 1 then we want to disable col3 and col4.
    Then the user will click on the Submit button.
    When he clicks on the Submit button then we want to set col4 to have a value of sysdate in the database table for any record where col2 had a value of 1.
    The next time the user comes to this screen he will select values for col3 and col4 of the records that col2 had a value of 2 (meaning col3 and col4 are enabled)
    This works fine if there is only one record in the report region.
    The problem is when we have more than one record.
    for example:
    Say we have two records...
    for record1 the user selects '1' for col2 and for record2 the user selects '2' for col2.
    When the user clicks on the Submit button col3 and col4 get disabled and col4 gets set to sysdate for record1, while col3 and col4 remain available but empty (because the user has not made a selection for these columns at this point) for record2.
    When the user comes back to this screen he now selects a value for col3 and picks a date for col4 for record2. When he clicks on the Submit button the value for col3 and the date entered in col4 for record2 should get updated in the database table and it is but the col3 value and the col4 date is being inverted with record1's data for some reason.
    Can you please tell me how to fix this?
    This is what the user has selected on the screen:
    (COL2) (COL3) (COL4)
    Requested? Granted? Response Date
    Record1 NO - 13-APR-09
    Record2 YES YES 20-APR-09
    After the user clicks on the Submit button this is how the screen displays it back:
    (COL2) (COL3) (COL4)
    Requested? Granted? Response Date
    Record1 NO YES 20-APR-09
    Record2 YES N/A 13-APR-09
    I am including the code from my update staement below:
    DECLARE
    A_ID NUMBER;
    requested NUMBER;
    grnted NUMBER;
    respdate DATE;
    f01 = AID ID
    f02 = REQUESTED YES OR NO
    F03 = GRANTED YES OR NO
    F04 = RESPONSE DATE
    BEGIN
    FOR i IN 1..HTMLDB_APPLICATION.G_F01.COUNT LOOP
    BEGIN
    A_ID      := HTMLDB_APPLICATION.G_F01(i); -- this is hidden
    requested := HTMLDB_APPLICATION.G_F02(i); -- (YES or NO)
    grnted := HTMLDB_APPLICATION.G_F03(i); -- (YES or NO)
    respdate := to_date(HTMLDB_APPLICATION.G_F04(i),'MM/DD/YYYY');
    EXCEPTION
    WHEN OTHERS THEN
    A_ID      := HTMLDB_APPLICATION.G_F01(i); -- this is hidden
    requested := HTMLDB_APPLICATION.G_F02(i); -- (YES or NO)
    grnted := 3; -- (YES or NO)
    respdate := sysdate;
    END;
    UPDATE TBL_AIT
    SET b_requested_id = requested,
    b_granted_id = grnted,
    b_response_date = respdate
    WHERE ait_id = A_ID;
    END LOOP;
    END;

    Hi,
    Any disabled items are not submitted with the page - therefore, your f03 and f04 collections would be one value short. This is a browser feature rather than an Apex feature.
    You can get around this by enabling all items before the submit takes place. Have a look at: Re: A better method of handling tabular forms with variable column type? This is for disabling items mainly, but includes an enableItems() javascript function that should help you.
    Andy

  • Need help updating OS 10.2.1

    I need to update my system software to 10.2.8. I have dial-up which is extremely slow, so I thought I'd update in parts rather than using the combo update. I had no trouble getting from 10.2.0 to 10.2.1. I've downloaded the 10.2.2 update three times. It seems to be working fine until I open the update icon. It says "The operation could not be completed. An unexpected error occurred (error code 1000)". I can't find anywhere what kind of error this is. I have an old imac. I didn't think that would matter since I'm already in 10.2.1. Any help would be greatly appreciated.

    Hi JEL,
    first of all: WELCOME TO THE DISCUSSIONS!
    The 10.2.8 Combo Update is 97 MB, the sum of all interim updates is more than 136 MB. Furthermore I saw, that the 10.2.5 Update is not online anymore. Use a download utility such as SpeedDownload or iGetter to download the 10.2.8 Combo update. With these you can interrupt, pause and resume any download.
    Also, do not forget to Repair permissions before and after an update!

Maybe you are looking for