Traversing in a loop weekly

Hi,
I have a loop in which I would like to Select query on weekly basis starting from the last date, essentially traversing backwards week-by-week.  For example the table below represents the sample data for the query within loop, without WHERE
clause.  What I like to get from the first iteration, say 5 years length backwards from the last date, which is 16/05/2014.  In the second iteration the last date would be 08/05/2014, because that is the next backward week date and again for
5 years period from that date.
II am not proficient with SQL especially when it comes to dates and I am looking for the neat approach as I have thousands of iterations and performance is the important factor here.
Thanks

If you don't need a massive table (centuries and centuries of dates, just a few years), you could use master..spt_values, but keep in mind the table I used only goes up to 2048, and you'll have creates something with a built in limit that you might reach
someday. 
There's also nothing wrong with using this table to CREATE permanent versions of the tables either (so you use it once, at table creation time, rather than over and over).  You can also join it to itself a time or two and use row_number() for the numbering
too.  There are 100 creative ways to achieve the same thing, as you've seen.  As long as they aren't giving wrong sequence numbers, pick whichever method you like best and that meets your needs.  (Most of the many articles you'll find are probably
correct also).
Most to the point though, I suggest making a permanent version of the calendar table (numbers table too), because once a person starts using a Numbers table and a Calendar table, they find lots of other reasons to use them that they hadn't thought of before
(or that they were doing a different way), and since you now are in that category, make yours permanent too!
EDIT: Also, there's a little paradigm shift taking place too: a natural reaction to creating a calendar table or numbers table with way more numbers than you need at the moment, is that it's wasteful.  Ok, don't create one so massive that it needs its
own dedicated server (unless you really need it), but remember, as a relational database, handling data in sets is what it does best, so don't worry too much about creating one that seems too big.  The overall benefit to you and your organization (standardization),
combined with the most likely outcome (no discernible performance difference, possibly even faster than create plus use on the fly) says just make the permanent table.

Similar Messages

  • Animation to loop 60 frames  in 24 hours

    I want to create an animation to loop 60 frames  in 24 hours and then pass on the following second day  repere
    (script)  thank you for helping me

    Sorry - bit sleepy when I last posted.
    If you want to have the SAME loop week after week, use
    on exitFrame me
       dString = the long date  -- "Friday, 25 October 2013"
       loopMarker = item 1 of dString  -- "Friday"
        go marker (loopMarker)
    end
    Make sure your markers match the first item of dString.
    If your French date string doesn't have a comma after the name day, or has a different layout, adjust "loopMarker =" accordingly

  • Tips and Tricks on optimizing your app for SDK 2.6

    If there is a thread like this I apologize for starting another one.
    The result from SDK 2.6 was a shellshock for me, but then again, it brings back the old days when I first struggled with the first version of the Flash Packager.
    I hope that we can put all our ways of optimizing apps for SDK 2.6 here.
    I do not claim superior knowledge, just what I have experienced from my own usage.
    Here’s mine [for now]:
    1: Do not use cacheAsBitmap and cacheAsBitmapMatrix when publishing using CPU.
    If your app uses iPhone/iPad combinations, this option will F you up.
    The size of the button will be wrong and all your wonderful "cached in the wrong resolution" size crap [Which shouldn’t happen because cache IS suppose to be a good thing, but SDK 2.6 doesn’t "always" work here for now, now I am not saying that it doesn't work, I am saying that upon certain unpredicatble refresh senerios you might see [I know I have] your buttons or graphics changed size upon redraw.]
    2: Do not use cacheAsBitmap and cacheAsBitmapMatrix in when publishing using GPU.
    Yes you heard that right; because the app will be slow slow slow.
    Basically SDK 2.6 renders these two options [cacheAsBitmap and cacheAsBitmapMatrix] completely useless and in many cases detrimental.
    The very key thing that speeds up apps in older version of the Flash packager is now the slo-mo dragger in the new SDK.
    What then do we use you ask ?
    I ask that question myself.
    But now we have new APIs!
    3: Approaching this new version of the SDK.
    I personally would suggest using this 2.6 SDK as a stepping stone to learning the new APIs but do not use it for actual app publishing unless you really need the multi-task.
    The speed problem will render your app professionally unusable for users comfortable with the reactionary speed of typical iPhone/iPad apps that even older version of the Flash packager can achieve if cacheAsBitmap and cacheAsBitmap matrix are used properly.
    Any more tips to share ?

    TIP: Just have a single ENTER_FRAME listener and add other listeners in a Vector. Example:
    public var enterFrameCallbacks : Vector.<Function>;
    public function initEnterFrameCallbacks():void {
         enterFrameCallbacks = new Vector.<Function>();
         stage.addEventListener( Event.ENTER_FRAME, fireEnterFrameCallbacks, true );
    public function addEnterFrameCallback( callback : Function ):void {
         enterFrameCallbacks.push( callback );
    private function fireEnterFrameCallbacks( e : Event ):void {
         e.stopImmediatePropagation();
         var i : uint;
         for (i = 0; i < enterFrameCallbacks.length; i++) {
              if (enterFrameCallbacks[i] != null) enterFrameCallbacks[i]();
    this is just a simple (untested) example.  Tips to make it even better:
    1) Store callbacks as linked list (faster traversal) instead of vector
    2) Add a 'remove' function
    3) Check for duplicates (if this is going to be a problem)
    4) Pass parameters to the callback (such as dt - or time since last frame)
    5) Implement this handler as a singleton, or a series of static methods, to allow easy access from anywhere
    Note that you may run in to problems with this code if:
    1) One of the callbacks removes itself or another callback from the list (because the vector changes as it is being traversed in the loop)

  • Accessing Parent Node of an XML through XSLT

    Hi,
    I want to loop at the child node and need to find out its parent node.
    Kindly let me know how to traverse back using XSLT.
    <u><b>sample source structure:</b></u>
    <level1>
         <level2>
           <level 3>
             <part number> 123 </part number>
           </level3>
           <level3>
              <part number> 1 </part number>
              </part number> 2 </part number>
           </level3>
         </level2>
    </level1>
    <u><b>target:</b></u>
    <group>
        <part Number> 123 </part number>
         <level3>  </level3>
         <level2>  </level2>
         <level1>  </level1>
    </group>
    <group>
        <part Number> 1</part number>
         <level3>  </level3>
         <level2>  </level2>
         <level1>  </level1>
    </group>
      <part Number> 2 </part number>
         <level3>  </level3>
         <level2>  </level2>
         <level1>  </level1>
    </group>
    Kindly let me know how to traverse back by looping at the part number.
    Regards,
    Swaroopa

    XML Transformation using XSLT
    Check XML file against XSD? Via XSLT?

  • Material shortage for Planned Order (Discrete Job) in PWB

    Client has planned orders on planner workbench (PWB) ready to release as Discrete Jobs but, because they have frequent revisions, they waits till all components (required to build job) are onhand before releasing from PWB.
    They would like an easy way to either check or be notified when the last component required for job is received into inventory so they can release from PWB. They cannot use the standard "Discrete Job Shortage Report" as the job is not created yet. And they don't want to release from PWB till ALL material is onhand
    Could we create a custom report perhaps (using same logic as "WIP Mass Load" to determine all component required versus onhand), but does anyone have a better solution how we can solve this?
    Regards,
    Hugh
    Edited by: user13050057 on 13-May-2010 02:09
    Edited by: Hugh Parker on 13-May-2010 08:13

    1) Why would you check for components of subassemblies? e.g. Say your BOM looks like this.
    FG1 is made up of SA1 and SA2 and COMP1.
    SA1 is made up of COMP2 and COMP3.
    Say you are releasing planned order for FG1. As long as the planned order is pegged to onhand for SA1, SA2 and COMP1, you are good. Right?
    2) If you have to add custom logic, I would do it using a when-validate-record personalization on the PWB. The personalization will call a function that accepts order number ; does all pegging checks and returns true or false. If it returns false, then the personalization returns error and does not allow release of the planned order. The function will have to be an interative program that traverses the pegging loop to ensure that all lowest level demands are pegged to onhand.
    Hope this helps
    Sandeep Gandhi

  • Optimizing 6.2.2

    We recently migrated from 5.02 Patch 4 to 6.2.2. The migration went successfully however we are having severe performance issues. We have worked with the data cache to try to enhance the performance however to no avail. Calc times after a restructure are about what they where before the migration however, when the database is calced the second time it takes about 3 times as long. HELP!!! We are very frustrated. Any recommendations would be most appreciated.ThanksLMKW

    TIP: Just have a single ENTER_FRAME listener and add other listeners in a Vector. Example:
    public var enterFrameCallbacks : Vector.<Function>;
    public function initEnterFrameCallbacks():void {
         enterFrameCallbacks = new Vector.<Function>();
         stage.addEventListener( Event.ENTER_FRAME, fireEnterFrameCallbacks, true );
    public function addEnterFrameCallback( callback : Function ):void {
         enterFrameCallbacks.push( callback );
    private function fireEnterFrameCallbacks( e : Event ):void {
         e.stopImmediatePropagation();
         var i : uint;
         for (i = 0; i < enterFrameCallbacks.length; i++) {
              if (enterFrameCallbacks[i] != null) enterFrameCallbacks[i]();
    this is just a simple (untested) example.  Tips to make it even better:
    1) Store callbacks as linked list (faster traversal) instead of vector
    2) Add a 'remove' function
    3) Check for duplicates (if this is going to be a problem)
    4) Pass parameters to the callback (such as dt - or time since last frame)
    5) Implement this handler as a singleton, or a series of static methods, to allow easy access from anywhere
    Note that you may run in to problems with this code if:
    1) One of the callbacks removes itself or another callback from the list (because the vector changes as it is being traversed in the loop)

  • Can somebody shine light on this Array problem I've got

    This is the error message I get when I run my code, I've looked at the array but can't see the problem.
    java.lang.ArrayIndexOutOfBoundsException
         at Test.main(Test.java:18)
    Exception in thread "main"
    I've set code below.
    Dave
    import corejava.Console;
    public class Test{
    public static void main (String[] args){
    int total = 0;
    int MealsInfo;
    int Week = 0;
    int Day = 0;
    int Meals[][] = new int[2][5];//2 columns 5 rows
    for(Week = 0; Week <2; Week ++){
    for(Day = 0; Day <5; Day ++){
    MealsInfo = Console.readInt("Please insert number of Meals" );
    Meals[Week][Day] = MealsInfo;
    total = Meals[Week][Day];
    System.out.println(Meals[Week][Day]);
    }

    FriedrichHoffmann in right.
    The ArrayIndexOutOfBounds Exception comes from the fact that after you exit a for loop the condition in the middle part of the for statement is false, so in the case of your for loops week == 2 and day == 5 when the for loops finish executing.
    As arrays are zero indexed (as you should already know) the last line should be
    System.out.println(Meals[Week-1][Day-1]);But this will only print out the last element in the array, what you want is to have the System.out call inside the second (nested) for loop.
    Hope this helps.

  • Hacker problems so I reloaded Snow Leopard. Afterwards, Mac had to delete 798 items. Now looping on 4 items to delete for the past 2 weeks. Can't reboot, reload, or restart. I have to let the battery run down for it to turn off. How to fix this, please?

    I had hacker problems so I reloaded Snow Leopard. Afterwards, Mac had to delete 798 items. Now it is looping on 4 items to delete for the past 2 weeks. I can't reboot, reload, or restart. I have to let the battery run down for it to turn off. I think a big part of the problem is that someon one the internet (the hacker) was mirroring my hard drive. It seems to have locked up my system. I could be wrong about this guess, though. All I do know is that it is now looping on the last 4 iems, and I can't do anything.
    Well, I can get it to turn on, but all it does is continously try to delete the last 4 items. When I try to reload Snow Leopard, it tells me my hard drive is full and that I need to delete items.
    Can anyone help? I am so lost without my Mac. I am back on the PC, and though it works, I'm sure many of you will understand when I say it's just not a Mac.
    Thanks.

    I installed Snow Leopard using my Apple external Superdrive. I followed directions I found on the Apple site. Here is the article info:  Mac OS X v10.6 Snow Leopard: How to Erase and Install  
                     Article HT3910
                     located at: http://support.apple.com/kb/HT3910
    Everything was going smoothly until I got to the reinstall part. I had to choose to reinstall on a hard drive or network drive. I've never used a network drive; just the hard drive. It seems that's where the troubles began. I selected the hard drive. It seemed to go well, and then I got the message that I needed to delete some files because I was out of space. I chose to get rid of my music files, but, there were only 636. I don't know what the rest of the files were. I was using the Secure Empty Trash command.
    That was my first time doing an erase and install. I tried to do it again, but I now get a continuous error telling me that my hard drive is full and I must delete files. Only I can't delete files because 4 files are still being deleted and my computer won't let me stop the process.
    I found out about the hackers mostly by the fact that whenever I used to watch something like Hulu or Netflix, I never had problems with internet connection or speed. Lately, I had internet connection problems. I went in to check my settings for my internet provider and found out the settings had been changed to public and all these extra computers were connected to my network.

  • How to traverse an array with a for-loop in this certain way...

    so I need to traverse an array starting from the first element, then from the last element, then the second element, then the second last element, then third element and so on... in a for loop
    how would that look in code?
    Any help would be appreciated, thanks!
    Edited by: inspiredone on Apr 4, 2008 6:34 AM

    Wow, that's a really clever and elegant way to do it promethuzz. I actually came up with something already before I read your post so yeah don't worry about me copying or anything. Mine is not as elegant/efficient and I definitely like yours a lot more but I will just share it anyway...it looks pretty similar to the second algorithm The_Matrix has provided. I figured this out from thinking how quicksort compares its pivot with the two indexes...
        int front=0;
        int back = a.length - 1;
        int counter =0;
        boolean switchflag = true;
        while(front<=back)
          System.out.println(a[counter]);
          if(switchflag)
            counter = back;
            front++;
            switchflag = false;
          else
            counter = front;
            back--;
            switchflag = true;
        } Anyways, thanks a lot for you guys help, promethuzz, The_Matrix, and newark.
    Edited by: inspiredone on Apr 4, 2008 11:25 AM
    Edited by: inspiredone on Apr 4, 2008 11:27 AM

  • Why do certain web screens go into loops on Safari? The problem just started last week.

    In the past week, whenever I have tried to access certain screens, including the Apple support screen, on Safari, it goes into a loop--reloading itself until it times out and gets an error screen.  I am sending this using Firefox, instead.  What could have changed?  I have reset my computer and done MacKeeper scans, to no avail.  I have Safari 5.1.8 and OS X 10.6.8

    So what do we do about it?  Without knowing what is causing a problem, I can't very well resolve it.

  • 1 week old iPhone4 stuck in Recovery mode loop

    Hi there
    today when I connected my ip4, iTunes asked me to download and install the latest iOS 4.0.2, after that it went into a recovery mode loop and I cant do muh more. I have so far tried to restore using 3 other pc´s, xp and Win7. Tried different USB cable, disable firewall/antivirus, but nothing helps. I am constantly getting an error 9, but I have seen error 2009 and 3194 as well (tried about 10 times so far).
    Dont know what else to try
    Thanks in advance for any feedback.

    I had same problem. When upgraded to 4.0.1 I had to take it to apple store to be reset. Tried everything. When it happened with 4.0.2 they gave me a new phone. Sadly I had to reload 30g of music/movie/app twice. Glad I have a better option if it happens next time.

  • IPhoto caught in import loop from photobooth import weeks ago

    About 3 weeks ago I imported a single photo from Photo Booth, and both iPhoto and Photo Booth froze. I forced quit both programs.
    NOW every time i open the program, it asks me if i want to "import the following duplicate photo" (the same Photo Booth photo i tried to import 3 weeks ago, now imported several times over). The problem happens everytime I return back to the ALREADY OPENED iPhoto using apple-tab or expose. The problem continues, regardless of what i choose at the prompt "cancel", "Don't Import", or "Import"
    Any ideas?
    I have already reset iPhoto, and deleted a plist file in Library, Application Support.
    I also deleted the file in Photo Booth.
    as an aside….
    I typically have some kind of freezing problem when I try to import photos into iPhoto when the program is closed.
    Thanks for your help! This makes iPhoto very annoying for me.

    Welcome to Apple Discussions,
    To try and resolve this issue you will be going into the iPhoto Library package. Make no changes in here other than those specified, as changes to the contents of the package can cause damage to your library and result in the loss of data. Always have a backup of your information: http://support.apple.com/kb/HT1553.
    __Close iPhoto
    __Go the location of your iPhoto Library (Located by default in Home > Pictures > iPhoto Library).
    __Ctrl + click or right click on the iPhoto Library and choose "show package contents".
    __Look for either an "Import" or "Auto Import" folder (or both).
    __Remove any items that might be in either folder.
    __Close the library and test iPhoto again.
    <hr>
    To help prevent this issue in the future:
    __Rebuild your iPhoto Library using the bottom 3 rebuild options following this kbase article: http://support.apple.com/kb/HT2638
    __Make sure you have enough available hard drive space. Open any Finder window and look at the bottom. The available space is what is free on your hard drive. Keeping 10-20 GB free at all times is wise to avoid performance issues.
    __Make sure you do not have File Vault enabled: http://docs.info.apple.com/article.html?path=Mac/10.6/en/8738.html
    Hope that helps.

  • I dropped my brand new iPhone in water and apparently my insurance doesn't cover eater damage. Is there any loop holes to get a new phone without paying full price, Can i upgrade my insurance and then send it in in a week or so?

    How long do you have to wait to make in insurance claim.

        kaebarber,
    We should take a closer look into some options for you. Normally insurance covers water damage. Which insurance do you have? Is it through Verizon Wireless?
    VanetrisC_VZW
    Follow us on Twitter @vzwsupport

  • 7344 servo motion switching between open and closed loop operation

    I have a custom end-of-line test system presently using a 4-axis 7344 servo controller to perform various functional tests on small, brushed DC motors. The system is programmed in C/C++ and uses flex motion functions to control the motor during testing. Motors are coupled to external encoder feedback and third party PWM drives running in closed-loop torque mode from an analog command signal. The system uses all four motion axis channels on the 7344 board to independently and asynchronously test up to four production motors at a time.
    In closed-loop mode, the system runs without issue, satisfying the battery of testing protocols executed by this system. I now have a request to add additional test functionality to the system. This testing must be run in open loop mode. Specifically, I need to use my +/- 10v analog output command to my torque drive to send different DAC output levels to the connected motor.drive while monitoring response.
    I do not believe the flex motion library or 7344 controller includes functions to easily switch between open and closed loop mode without sending a new drive configuration. I am also under the impression that I cannot reconfigure one (or more) servo controller axis channels without disabling the entire drive. As my system runs each axis channel in an asynchronous manner, any requirement to shutdown all drives each time I change modes is an unworkable solution.
    I am open to all ideas that will allow asynchronous operation of my 4 motor testing stations. If the only solution is to add a second 7344 controller and mechanical relays to switch the drive and motor wiring between two separately configured servo channels, so be it. I just want to explore any available avenue before I place a price tag on this new system requirement.
    Bob

    Jochen,
    Thank you for the quick response. The 7344 board does an excellent job running my manufacturing motor assemblies through a custom end-of-line tester in closed loop mode. A portion of the performance history and test result couples the motor through a mechanical load and external shaft. The shaft is in contact with a linear encoder that closes my servo loop.
    My new manufacturing requirement is to also sample/document how the small DC motor behaves in open loop operation. Your solution is exactly what I need to perform the additional functional tests on the product I am manufacturing. I see no reason why this cannot work. I was originally concerned that I would need to reinitialize the 7344 board after changing axis configuration. Initialization is a global event and impacts all four channels on the 7344 board.
    Using flex_config_axis() to change axis configuration on a single channel without disturbing other potentially running axis channels will solve my concern. It will be several weeks before I can return to the manufacturing facility where the 7344-based testing machine is located. I will update this thread once I verify a successful result.
    Bob

  • Windows Update in Endless Loop of 'Installing updates" and "Undoing changes" on New Windows 8.1 Pro Install

    I am setting new Windows 8.1 Pro computers, and am installing Windows 8.1 Pro to bare drives.  Everything goes fine until Windows Update starts installing updates, and then the computer goes for hours installing updates, and then "We
    could not complete the updates Undoing changes".   It's an endless loop. It seems to be the same 38 updates.  This is a recent phenomenon.  I have not run into this until the last week or two on several new computer installs.
    Again these are brand new installs, so something is clearly wrong with the Windows updates.
    If anyone can please tell me how to avoid this, it would be much appreciated.
    Michael

    Hi Michael,
    "  This is a recent phenomenon"
    Have you made any modifications to the machines ?
    To resolve this issue ,running the built-in troubleshoot tool is a very good beginning .It will automatically diagnostic the windows update components and check the configurations for us .
     Control Panel\All Control Panel Items\Troubleshooting\Fix problems with Windows Update
    If there are antivirus software installed in these machines, please turn off them temporarily to have a check.
    The command line included in the link as S.Sengupta posted is very useful and convenient to repair the windows corrupted files .We can have a try .
    "sfc /scannow" ,"DISM.EXE /online /cleanup-image /restorehealth "
    We also can check the windowsupdate.log for more information to troubleshoot this issue .
     Run "windowsupdate.log"
    If you have trouble in analyzing the log ,please upload them to the OneDrive and paste the link here .
    Best regards

Maybe you are looking for

  • How I can send a message to the person who have my phone?

    Hi! I lost my phone and the person who have it is taking pictures and they are uploading to my photo stream.  There is any way to send her a message that I am the owner and I want my phone back? 

  • What tags I need to put a link in my text?

    Hi there, I just want to place a link in my post and not the full address, just to let people click in a word. How do I do that?

  • Export part of library

    In the beta i belive there was an option to export a port of the library to then import it into another Lightroom. Say 2 photographers wanting to move part of the library among each other ? Is that gone in the 1.0 ? /thomas

  • Ipod connection problem, not seen by comp. HELLLLLPPPP

    After choosing to restore my ipod the message 'itunes needs to prepare your ipod for recovery. Please leave your ipod connected'. I click continue. It prepares ipod for recovery, before saying 'waiting for ipod' even though its connected, it then rep

  • Pivot Table generation using ABAP code

    Hi Friends,               Could you please anyone help me to get the functionality of generating Pivot table in Excel from SAP. and let me know how to use the structure EXCELPIVOT. I am very greatful if anyone get me for this.