To automate query such that it works even during cross year.

Hi all, please help....
Firstly, certain parameters need to be understood.
Our financial year ended this september and new
financial year begins October.
Month_ID
Aug'03 = 71
Sep'03 = 72
Oct'03 = 73
Nov'03 = 74
etc...
Month_Id increases continously regardless of new financial year.
Period_ID
11 (Aug
12 (Sep)
1 (Oct)Period changes to 1 again coz our coy's
financial year period starts in October.
Now, the main part of the SQL statement causing cross year problem is this:-
WHERE MONTH_ID BETWEEN MONTH_ID-(PERIOD_ID-1) AND MONTH_ID-1
Firstly, for last month September:-
Between Month_ID - (Period_ID-1) and Month_ID - 1
72 - (12-1) 72 - 1
=Between 61 and 71
The calculation is correct for September.
Now for October, this is the new financial year and the
Period_id has now changed from 12 to 1.Month_ID has now increased to 73.
Between Month_ID - (Period_ID-1) and Month_ID - 1
73 - (1-1) 73 - 1
= Between 73 and 72
This statement is obviously wrong.
Folks, is there anyway I could fine tune the SQL to automate this so that it works during all cross year periods?
Here is the actual full SQL statement just for your reference:-
SELECT
B.YEAR, B.PERIOD_ID-1,
ROUND(SUM(A.DEL_HC_TO_AMT),2) YTD_DEL_HC_TO_AMT, C.CUST_ID,
C.COUNTRY_ID, C.CUST_GROUP, C.FIN_GRP_ID
FROM
DWMART.DWHD10_SLS_DELIVERY A,
DWMART.DWHMAS_TME_MONTH B,
DWMART.DWHMAS_CUS_MASTER C
WHERE A.MONTH_ID BETWEEN B.MONTH_ID-(B.PERIOD_ID-1) AND B.MONTH_ID-1
AND A.ITEM_ID NOT LIKE 'FR%'
AND A.ITEM_ID NOT LIKE 'NON%'
AND TRUNC(SYSDATE) BETWEEN B.START_DATE AND B.END_DATE
AND A.CUST_ID = C.CUST_ID
GROUP BY B.YEAR, B.PERIOD_ID-1, C.CUST_ID, C.COUNTRY_ID, C.CUST_GROUP, C.FIN_GRP_ID
Thanx guys.

Its not clear what you are wanting to get back from your query.
If for october you want the full previous financial year, and the other months are currently correct, you could implement a case...
WHERE a.MONTH_ID BETWEEN
  case b.period_id
    when 1 then b.MONTH_ID - 12
    else b.MONTH_ID-(b.PERIOD_ID-1)
  end
  AND b.MONTH_ID-1

Similar Messages

  • I have a Targus Versavue bluetooth keyboard that has worked perfectly for 2 years.  It lost connection yesterday.  I charged the battery but it still won't connect.  Help ??

    I have a Targue Versavue bluetooth keyboard that has worked perfectly for 2 years.  It lost connection yesterday.  I charged the battery but it still won't connect.  I just get a blinking blue light.  Help ??

    Look at iOS Troubleshooting Wi-Fi networks and connections  http://support.apple.com/kb/TS1398
    iPad: Issues connecting to Wi-Fi networks  http://support.apple.com/kb/ts3304
    iOS: Recommended settings for Wi-Fi routers and access points  http://support.apple.com/kb/HT4199
    Additional things to try.
    Try this first. Turn Off your iPad. Then turn Off (disconnect power cord) the wireless router & then back On. Now boot your iPad. Hopefully it will see the WiFi.
    Go to Settings>Wi-Fi and turn Off. Then while at Settings>Wi-Fi, turn back On and chose a Network.
    Change the channel on your wireless router. Instructions at http://macintoshhowto.com/advanced/how-to-get-a-good-range-on-your-wireless-netw ork.html
    Another thing to try - Go into your router security settings and change from WEP to WPA with AES.
    How to Quickly Fix iPad 3 Wi-Fi Reception Problems
    http://osxdaily.com/2012/03/21/fix-new-ipad-3-wi-fi-reception-problems/
    If none of the above suggestions work, look at this link.
    iPad Wi-Fi Problems: Comprehensive List of Fixes
    http://appletoolbox.com/2010/04/ipad-wi-fi-problems-comprehensive-list-of-fixes/
    Fix iPad Wifi Connection and Signal Issues  http://www.youtube.com/watch?v=uwWtIG5jUxE
    Unable to Connect After iOS Update - saw this solution on another post.
    https://discussions.apple.com/thread/4010130?tstart=60
    Note - When troubleshooting wifi connection problems, don't hold your iPad by hand. There have been a few reports that holding the iPad by hand, seems to attenuate the wifi signal.
    ~~~~~~~~~~~~~~~
    If any of the above solutions work, please post back what solved your problem. It will help others with the same problem.
     Cheers, Tom

  • I have a time capsule that has worked flawlessly for several years.  I recently upgraded my iMac OS to 10.8.4 and coincidently (or not) have started having some issues with backups.  When I go into time machine, it struggles to find the time capsule disk

    I have to unplug my time capsule and reboot it.  Is there a diagnostic routine I can run or any error detection I can look for?

    You are absolutely right.. when apple changed significant features in Lion and Mountain Lion .. they introduced a bunch of issues into networking which are bugs to this day..unacknowledged.. and without much that will fix them.. other than your reboot strategy.. which is like.. well that other OS.. where continual reboots are considered normal.
    Old TC may also just suffer from age.. we continually tell people they have a lifespan.. 3years is the reliable span.. after that expect anything.. sudden death.. slow decline.. continual hassles and problems. If the backups are important to you.. then it is telling you in a very clear way.. replace me.. I am no longer happily providing services promised.
    Now to specifics.. we don't know what the problem is.. if we knew we could give some work around.
    The problem is odd in that it doesn't affect everyone.. if it starts .. people find it starts several months in to ownership.. it is never cured.. or even curable.. something like DNS or ARP table is being lost.. but it is not either of those things.
    Is there a diagnostic routine I can run or any error detection I can look for?
    Nothing much shows up anywhere. Including the TC log or local logs. It simply has lost the TC disk but not internet.
    So.
    Some things do help.
    I don't know if you have pondini's resources.. TM is a complex piece of software.. it has multiple issues.
    http://pondini.org/TM/Troubleshooting.html
    Look at A1 .. load the widget.
    A5 .. verify the backup.
    A4 .. reset TM.
    All of those things can help.. look at some of the typical problems.. C12 and C17 being the most common since Lion.. and exacerbated in Mountain Lion.. not fixed.
    Some suggestions.
    1. Keep names short, no spaces and pure alphanumeric. See C9 http://pondini.org/TM/Troubleshooting.html
    2. Do not use 7.6.3 firmware... go back to 7.6.1 or even better 7.5.2 on an old one.
    Firmware downgrade is easy in new utility. Hold down the option key whilst selecting version.
    3. I recommend a very short dhcp lease time.. 20min for example. In whatever device is the router .. that can help keep things up to date.. and use dhcp reservation again to see if the address info helps to keep things updated.
    4. Do turn on ipv6 local link.. which you need to anyway with 6.3 utility.
    http://support.apple.com/kb/TS4597
    5. If you are using a desktop.. an external drive is faster.. more reliable and easier than TC for Time Machine backups..
    6. Consider using CCC or another backup software.. if you want to continue to use network drive.
    7. Although using 6.3 airport utility has some advantages.. it is also devoid of a lot of tools that are in v5.6 airport utility.. well worth loading into at least one computer on the network.. if you only have Mountain Lion now here is one method.
    How to load 5.6 into ML.
    1. Download 5.6 for Lion.
    http://support.apple.com/kb/DL1482
    Click to open the dmg but do not attempt to install the pkg.. it won't work anyway.
    Leave the package open on the desktop so you can see the file. AirportUtility56.pkg
    2. Download and install unpkg.
    http://www.timdoug.com/unpkg/
    Run unpkg on the desktop.. If your Mac refuses to run the software, because it wasn’t downloaded from the Apple store, go to security in preferences and allow other software to work.. this is limitation of trade methinks. You can set back later if you like.
    Now drag the AirPortUtility56.pkg file over to unpkg.. and it will create a new directory of the same name on the desktop.. in finder, open the new directory, drill down.. applications, utilities .. there lo and behold is Airport utility 5.6 .. drag it to your main utilities directory or just run it from current location.
    You cannot uninstall version 6 (now 6.3 if you updated) so don't try.. and you cannot or should not run them both at the same time.. although I have had no problems when doing so.
    For screen shots see this post.
    https://discussions.apple.com/thread/4668746?tstart=0

  • HT2248 G5 will now not recognize 2 added dimms that have worked perfectly for 3 years

    Added 2 x 500 dimms 3 years ago, has been fine up until recently. But now the computer is running very slow and have discovered it is not showing or recognizing that the extra memory is there. It is showing only the original 2 x 256 dimms and nothing in the other slots. Anyone experienced anything similar?

    Take a soft gum type eraser and rub the contacts on the RAM.
    Look at this link: Testing RAM @ http://guides.macrumors.com/Testing_RAM Then download & use Memtest & Ramber.
    Do you have an Apple Hardware Test disc? Running the Apple Hardware Test in Loop Mode is an excellent troubleshooting step for finding intermittent hardware problems. It is especially useful when troubleshooting intermittent kernel panics. If Loop Mode is supported by the version of the Apple Hardware Test you are using, you run the Extended Test in Loop Mode by pressing Control-L before starting the test. Looping On should appear in the right window. Then click the Extended Test button.The test will run continuously until a problem is found. If a problem is found, the test will cease to loop, indicating the problem it found. If the test fails, be sure to write down the exact message associated with the failure.In some cases, RAM problems did not show up until nearly 40 loops, so give it a good run.
     Cheers, Tom

  • Hi. There is a ghost search bar on my iMac screen which flashes constantly, even during start up and shut down. How can i make this go away? Please help. x

    Hi There is a ghost search bar on my iMac that flashes continually, even during start up and shut down. How can i make this go away? Please help. x

    Please read this whole message before doing anything.
    This procedure is a test, not a solution. Don’t be disappointed when you find that nothing has changed after you complete it.
    Step 1
    The purpose of this step is to determine whether the problem is localized to your user account.
    Enable guest logins* and log in as Guest. Don't use the Safari-only “Guest User” login created by “Find My Mac.”
    While logged in as Guest, you won’t have access to any of your documents or settings. Applications will behave as if you were running them for the first time. Don’t be alarmed by this behavior; it’s normal. If you need any passwords or other personal data in order to complete the test, memorize, print, or write them down before you begin.
    Test while logged in as Guest. Same problem?
    After testing, log out of the guest account and, in your own account, disable it if you wish. Any files you created in the guest account will be deleted automatically when you log out of it.
    *Note: If you’ve activated “Find My Mac” or FileVault, then you can’t enable the Guest account. The “Guest User” login created by “Find My Mac” is not the same. Create a new account in which to test, and delete it, including its home folder, after testing.
    Step 2
    The purpose of this step is to determine whether the problem is caused by third-party system modifications that load automatically at startup or login, by a peripheral device, by a font conflict, or by corruption of the file system or of certain system caches.
    Please take this step regardless of the results of Step 1.
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards, if applicable. Start up in safe mode and log in to the account with the problem. You must hold down the shift key twice: once when you turn on the computer, and again when you log in.
    Note: If FileVault is enabled, or if a firmware password is set, or if the startup volume is a software RAID, you can’t do this. Ask for further instructions.
    Safe mode is much slower to start up and run than normal, with limited graphics performance, and some things won’t work at all, including sound output and Wi-Fi on certain models. The next normal startup may also be somewhat slow.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    Test while in safe mode. Same problem?
    After testing, restart as usual (not in safe mode) and verify that you still have the problem. Post the results of Steps 1 and 2.

  • After updating my iPhone 5 to iOS 8.1 it will not connect to the wifi network at work even though it recognizes it. It however still automatically connects to the network at home. I have restared the phone and toggled the router, still no connection

    After updating my iPhone 5 to iOS 8.1 it will not connect to the wifi network at work even though it recognizes it. It however still automatically connects to the network at home (this is the network I used to update the phone). My iPad however does not seem to have any problem connecting. I have restared the phone, toggled the router, re-entered the network password but there's still no connection.

    When your device is trying to connect to the work Wi-Fi network, go to Settings > Wi-Fi > then tap on the name of the Netowrk that she is having trouble with. Then tap on forget this network. Let the device attempt to connect again and make absolutely sure she is trying to connect to the work network and not a nearby network, then make absolutely sure the password is entered correctly.

  • My laptop thinks there are headphones in at all times, such that the speakers won't work, how do I fix this?

    My laptop thinks there are headphones in at all times, such that the speakers won't work, how do I fix this?

    Thanks but that did not work. Details: when I don't have headphones plugged in, the volume won't go up or down and it also displays a circle with a line through it meaning it's not working. When I go to settings and look at my audio output, it only says headphones, even if no headphones are plugged in. I have tried inserting and removing headphones many times, also tried poking the inside of the headphone jack with a stripped Q-tip, and nothing works. Something inside the jack that senses headphones is not sensing the lack of headphones.

  • How does one set options such that the entry for a successfully downloaded file automatically got removed from the download window?

    In earlier versions of Firefox, I could set options such that when a download completed successfully, the download entry was automatically removed from the download windows. I don't seem to be able to get this functionality in ver 13.0.1. In this version, i have to right click on each completed download entry, and choose "remove from List". This is very cumbersome.
    I really liked the earlier auto cleanup as it left only pending, current and failed downloads in the Download window - just the stuff I needed to pay attention to. Is there any way to set up ver 13.0.1 to make things work the way they worked so well earlier.
    A related issue may be that in the Privacy tab, the option for Browsing and Download history have been combined (were they separate earlier? - don't remember). I want to keep my browsing history but not my download history. I can still clear them individualy in the "Clear Recent History" settings, so why can't I set the control for keeping either individually? Or can I?

    The download history is part of the regular browsing history, so you would have to disable the history altogether as you've already noticed.
    * Tools > Options > Privacy > History: Firefox will: "Use custom settings for history"
    **"Remember my browsing and download history"
    Firefox manages the downloads in the Downloads folder in the Library.
    * Firefox > History > Show All History > Downloads
    Future Firefox versions won't use the current download manager (pref: browser.download.useToolkitUI; Bug 726444), but use a toolbar button with a drop down list, similar to the Bookmarks Menu button.

  • Firefox ver. 3.6 stopped loading pages of any kind. Even Google or Facebook! Maybe it's because I tried to download a program that didn't even open up. All other browsers work normally.

    My Firefox ver. 3.6 stopped loading pages of any kind. Even Google or Facebook! I don't know how this happened. May it is because I tried to download a program that didn't even open up.... But I don't know how to make it work. All other browsers work normally, and I'm scanning for viruses even though my anti-virus did not warn me of anything... I tried to download a keygen and this is what happened. I can't figure out what it is. Not a connection problem. I even tried to uninstall an re-install firefox, but still nothing worked.

    Your issue may be caused by Malware. You can run and update the following '''free''' anti virus software:
    1. Malwarebytes (Free version) - http://www.malwarebytes.org
    2. Spybot Search & Destroy - http://www.safer-networking.org
    3.Spyware Terminator - http://www.spywareterminator.com
    In addition, there are a number of forums you can use to help get rid of your infection. These include:
    *http://www.bleepingcomputer.com/forums/
    *http://forums.spybot.info/
    *http://www.spywarewarrior.com/index.php

  • HT3529 My phone bill is paid and I can't send or receive msgs and I tried to call Rogers but that doesn't even work and if it was a bill issue I could still call Rogers think it might be software but I would like to know what to do

    My phone bill is paid and I can't send or receive msgs and I tried to call Rogers but that doesn't even work and if it was a bill issue I could still call Rogers think it might be software but I would like to know what to do

    I'm sorry to learn that you are not able to make/receive calls chelseabee! (ticket number removed) results indicate that there is no issues with the network or account provisioning. Since you have already done a hard reset http://vz.to/1gBkSJc (as per your post), I recommend exploring replacement options. If your phone is within the one year manufacturers' warranty we can provide a Certified Like New replacement http://vz.to/uyYF0o as long as no physical/liquid damage exist. If your phone has sustained physical/water damage and you have insurance, you can submit a claim to the insurance company online at this link http://bit.ly/07CrqPK
    AntonioC_VZW Follow us on Twitter at www.twitter.com/VZWSupport
    >> Edited to comply with the Verizon Wireless Terms of Service <<
    Edited by:  Verizon Moderator

  • I have made a website using iweb, as this will no longer be supported by apple, does that mean the gallery I have created on my website will no longer work even though I am hosting it with a different hosting provider

    I have made a website using iweb, as this will no longer be supported by apple, does that mean the gallery I have created on my website will no longer work even though I am hosting it with a different hosting provider. Will the other widgets no longer work?

    There are a few things that won't work on other hosting sites; hit counters and pop-up slide shows for sure.
    See http://oldtoadstutorials.net/No.iW11.html for more info, and/or the iWeb forum at https://discussions.apple.com/community/ilife/iweb

  • IPad mini now terrible to use, apple support no help because warranty is up.  All cause by new ios8 update, wifi issues, many apps no longer work, apps that do work now crash regularly and sometimes take several instances and reboots to even open.

    IPad mini now terrible to use, apple support no help because warranty is up.  All cause by new ios8 update, wifi issues, many apps no longer work, apps that do work now crash regularly and sometimes take several instances and reboots to even open.

    need help uninstalling ios8 and going back to 7 where things worked please.

  • I tried updating my iPhone3g through itunes. Now i'm stuck in recovery mode and i've EVERYTHING even websites and such but nothing worked out! I've also tried restarting and fiddling with the home button but nothing still worked. Please help!

    I tried updating my iPhone3g through itunes. Now i'm stuck in recovery mode and i've EVERYTHING even websites and such but nothing worked out! I've also tried restarting and fiddling with the home button but nothing still worked. Please help! What should I do??

    Well, if you've indeed tried EVERYTHING, then you'll need to bring your phone to Apple for evaluation.

  • I am suddenly unable to update or download apps on my iphone 3G.  It says "the download will be available after you log in to itunes from your computer." I never had to do that before.  Even when I do log in from the computer, it still doesn't work.

    I am suddenly unable to update or download apps on my iphone 3G.  It says "the download will be available after you log in to itunes from your computer." I never had to do that before.  Even when I do log in from the computer, the download still doesn't work.  So what's going on?  Why would I need to go the computer to download an app to my phone?  That defeats the whole purpose of having the phone, which is to do stuff when you are not at the computer!@!@  Any help greatly appreciated.  Thanks.

    - Try a reset. Nothing will be lost
    Reset iPod touch:  Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset network settings: Settings>General>Reset>Reset Nework Settings. You will have rejoin networks
    - Go to Settings>Store and sign out of account and sign back ino
    Do you have a very slow wif connection on the iPod?
    Have you tied connecting to another network?

  • My iTunes won't update, it starts to install then just says it can't. I decided to try uninstall it but it won't even uninstall anymore, there is some type of ERROR going on. I tried to just install iTunes from the website and that won't even work.

    My iTunes won't update, it starts to install then just says it can't. I decided to try uninstall it but it won't even uninstall anymore, there is some type of ERROR going on. I tried to just install iTunes from the website and that won't even work. I'm using a Windows Vista.

    Hi there,
    I've got a couple of articles that may help you out. This first one goes over how to properly remove and reinstall iTunes.
    Removing and reinstalling iTunes, QuickTime, and other software components for Windows Vista or Windows 7
    http://support.apple.com/kb/HT1923
    This next one goes over some of the troubleshooting steps if you are having issues reinstalling iTunes.
    Trouble installing iTunes or QuickTime for Windows
    http://support.apple.com/kb/HT1926
    Hope that helps,
    Griff W.

Maybe you are looking for

  • Transfer Information to This Mac from Encrypted Time Machine?

    I just got a new Macbook Pro (factory fresh) and wanted to move my data from my Encrypted Time Machine (on a USB drive).  The older Mac that I'm moving of off is running the 10.7.2 and I have been back it up daily to my Time Machine disk. I attach th

  • Help!  Trouble transferring videos to iPod

    Hi! I really need some help here, I e-mailed the iTunes store and called tech support and neither one helped. I have a Dell Inspiron 8600 laptop computer with Windows XP and a Fifth Generation 30 GB video iPod. I purchased a season of television show

  • Cannot drop pictures into video effects window (not the usual problem)

    Hi there, I cannot drop jpgs into the video effects window. I checked http://discussions.apple.com/thread.jspa?messageID=5700460&#5700460 and http://discussions.apple.com/thread.jspa?messageID=7384222&#7384222 and they got me going, but my issue is s

  • Line By Line Comparison of 2 Html Pages

    Does anyone know of an algorithm that will compare 2 pages together, line by line? Many source control applications have this functionality.

  • Multi-function printer compatibility

    I have read in a few places that a multi-function printer (print, scan, fax, copy) will not work with all of the computers on the network plugged in to the USB port of the time capsule to anyone that has the time capsule, is this true? will all compu