DATEDIFF inconsistencies when report range crosses years

Hi folks -
I have a requirement for a software metering report that provides prompted month ranges for usage activity - for what good reason, I still have not been told.  At any rate cannibalized a few reports to arrive at the following.  When I check
the output of the number of months chosen, it seems to work fine when I use ranges in the same year, but when I choose 12/2013-6/2014 for example I get larger numbers that don't total up to the number of months.  Can anyone please take a look at my query
and see if I am missing something?  Maybe I'm just not understanding DATEDIFF and am not giving it the proper values.  Sorry - we're still on 2007 and I know many have moved to 2012.  Also I notice when I give it an out of bounds parameter,
like ending date of 7/14, for which I don't have any summarized data yet, it returns nothing.  How could I make it revert to the previous month for which data exist? 
Thanks for any help!!!
declare @TimeKey int
declare @months float
declare @endTimeKey int
set @TimeKey=100*@Year+@Month
set @endTimeKey=100*@endYear+@EndMonth
select @TimeKey
select @endTimeKey
select @months=DATEDIFF(d,@timekey,@endTimeKey)
from v_SummarizationInterval where TimeKey>=@TimeKey and TimeKey< @endTimeKey
select @months
if IsNULL(@months,0) > 0
select
sys.Netbios_Name0, mf.productname, MAX(mf.meteredfileversion) as 'Product Version',
sys.User_Name0, v_GS_SYSTEM_CONSOLE_USAGE_MAXGROUP.topconsoleuser0,v_R_User.displayName0 as 'User Display Name',
MAX(v_RA_User_UserOUName.User_OU_Name0) as 'User OU', v_R_User.unique_user_name0 as 'FQ User Name',
v_R_User.telephonenumber0 as 'Telephone', v_R_User.mail0 as 'E-Mail',
DATEADD(ss,@__timezoneoffset,MAX(mus.LastUsage)) as LastUsage,
SUM(UsageCount) + SUM(TSUsageCount) as C021,
ROUND((SUM(UsageCount) + SUM(TSUsageCount))/(@months*30),2) as C022,
ROUND(SUM(UsageTime)/60.0,2) as C023,
ROUND(SUM(UsageTime)/60.0/(SUM(UsageCount) + SUM(TSUsageCount)),2) as C024,
ROUND(SUM(UsageTime)/60.0/(@months*30),2) as C025
from v_R_System sys
join v_MonthlyUsageSummary mus on sys.ResourceID=mus.ResourceID
join v_MeteredFiles mf on mus.FileID=mf.MeteredFileID
left join v_RA_System_SMSInstalledSites inst on sys.ResourceID=inst.ResourceID
full join v_R_User on sys.user_name0 = v_R_User.user_name0
left outer join v_RA_User_UserOUName on v_RA_User_UserOUName.ResourceID = v_R_User.ResourceID
left join v_GS_SYSTEM_CONSOLE_USAGE_MAXGROUP on v_GS_SYSTEM_CONSOLE_USAGE_MAXGROUP.ResourceID = sys.ResourceID
where mf.ProductName = 'Adobe Acrobat'
and mus.TimeKey =@endTimeKey
group by sys.Netbios_Name0, sys.User_Name0, v_R_User.displayName0, v_R_User.unique_user_name0,
v_R_User.telephonenumber0, v_R_User.mail0, mf.productname, V_GS_SYSTEM_CONSOLE_USAGE_MAXGROUP.topconsoleuser0
having SUM(UsageCount) + SUM(TSUsageCount) > 0
order by sys.Netbios_Name0
--Month Prompt
begin
if (@__filterwildcard = '')
select distinct DATEPART(month,IntervalStart) as Month, DATEPART(year,IntervalStart) as Year from v_SummarizationInterval order by DATEPART(year,IntervalStart), DATEPART(month,IntervalStart)
else
select distinct DATEPART(month,IntervalStart) as Month, DATEPART(year,IntervalStart) as Year from v_SummarizationInterval
WHERE DATEPART(month,IntervalStart) like @__filterwildcard
order by DATEPART(year,IntervalStart), DATEPART(month,IntervalStart)
end
--Year Prompt
begin
if (@__filterwildcard = '')
select distinct DATEPART(year,IntervalStart) as Year from v_SummarizationInterval order by DATEPART(year,IntervalStart)
else
select distinct DATEPART(year,IntervalStart) as Year from v_SummarizationInterval
WHERE DATEPART(year,IntervalStart) like @__filterwildcard
order by DATEPART(year,IntervalStart)
end
--EndMonth and EndYear prompts mirror the above

I’m cleaning up old, post did you figure this out yet, if so how?
Garth Jones | My blogs: Enhansoft and
Old Blog site | Twitter:
@GarthMJ

Similar Messages

  • POS data variation in bw report for fiscal year

    HI ,
    I got issue from User like ,In a BW report I have given sold to party as best buy with actual sel though and fiscal year form 2006 to 2008.I got some values with factory week 14/2009 for it.But when i selected fiscal year 2007 to 2008 i got some other value for factory week 14/2007 which is not matching with previous value when i drilled down fro Fiscal year 2006 to 2008.Please tell me hwo to proceed wiht this issue .

    If I would come across this problem, I would perform following checks.
    - Run Query for 2006 - 2007 (Check and note down the value for 14/2007)
    - Run Query for 2007 - 2008 (Check and note down the value for 14/2007).
    MAKE SURE THAT YOU HAVE USED SAME SELECTION CRITERIA OTHER THAN YEAR.
    Then check your cube data, put the same selection in the cube and check the data for the week 14/2007 and see which value of the above two noted value is correct.
    You may also want to check if there is any other restriction based on year selection in the query. If any KFs are restricted by some more values based on the fiscalyear selection.
    - Danny

  • Display Chinese Word In Crystal Report's Cross-Tab

    Hi all,
    I am trying to display chinese word in my cystal report. It can be display correctly in detail, page header or formula. But when come to cross-tab, it just will show some funny symbol on it. any idea?
    i am using Crystal report xI release 2.
    Thank You
    Wong

    Hi,
    I solve it.Just for your reference, change the font type inside cross-tab.

  • S_P00_07000134 Withholding Generic Report for Fiscal year 2009

    Hi All,
    I was executing S_P00_07000134 Withholding Generic Report for Fiscal year 2009 but when the output came in the output I can see the year 2008 instead of 2009. So hown can I bring 2009 in my report.
    IS there any SAP not whic needsto be applied.
    REgards,
    Kiran C

    Dear,
    What is the reporting period that you have given in this report, try to give 01.01.2009-31.12.2009 if it is a calendar year or as per your fiscal year give the period.

  • 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

  • Curve 8520 cannot send/receive calls or SMS when in range of WiFi - since foreign holiday

    Re-posting this in the Curve forum, where it belongs... hoping someone can help.
    Recently the whole family went to Spain for two weeks. All four of our phones (a Google Nexus 4, a BB Curve 9300 and two BBCurve 8520s) worked OK in Spain, connected to local mobile networks, sent and received texts and so on.
    Since returning to the UK, the BlackBerry handsets have all had problems getting re-registered to our home network (giffgaff, which uses the O2 network, as I understand it). The nexus has been fine from the moment we got back, but the BB handsets are not.
    The symptoms: when in range of a registered WiFi connection, the phones cannot send or receive texts (SMS) or make or receive calls, when out of range of WiFi, they do (sometimes) succeed. It is as though the WiFi settings are over-ruling the service books / HRT for the mobile network.
    The 9300 seems to have sorted itself out, thanks (possibly) to an OS upgrade. The 8520s remain basically useless.
    We have tried: battery pulls, SIM pulls, manual network registration, clearing the service books and re-registering, switching SIM cards between the phones (whichever SIM is in the 9300 works OK, whichever SIM is in the 8520 does not work), OS upgrade.
    The network shows on the handset screen, and connection is shown as EDGE. But calls do not get connected and SMS messages fail with "too many retries". Attempts to re-register the handset result in a message being received that the handset has been registered but it makes no difference.
    The network provider (giffgaff) say they have done everything they can, and I should speak to "an engineer" - but it seems very unlikely to me that all three phones suffered a hardware fault while flying home from Spain, and that the 9300 somehow fixed itself. So I'm convinced it is a registration issue, but giffgaff are not exactly confident in their support for BB.
    So - has anyone ever seen this behaviour before, and how can we fix it?
    Thanks

    Good day
    I took a into the BlackBerry knowledge data base here is some info you can follow
    I cannot make or receive calls
    I cannot send SMS text messages
    Want to contract me? You can follow me on Twitter @RobGambino
    Be sure to click Like! for those who have helped you.
    Click Accept as Solution for posts that have solved your issue(s)!

  • Export to Text failing when Report height is more than 23 inches

    I have a problem while exporting to Text, when report height is more than 23 inches. It's failing with "an unhandled exception occurred in crw32.exe [3856]"
    Both Crystal Reports 2008 and Crystal Reports XI Release 2 are failing. Export to PDF is working fine.
    I am trying to design a lengthy report and export to text.
    I searched in forum with out any results.
    It would be great, if some body can point me in right direction. Thank you.
    Regards,
    Raveendra

    Hi Raveendra
    To work around this error message, disable DEP by performing the following steps:
    1. Click Start > Settings > Control Panel.
    2. Double-click 'System'. The "System Properties" dialog box appears.
    3. Click the 'Advanced' tab.
    4. Click 'settings' under 'performance'.
    5. Click the 'Data Execution Prevention' tab
    6. Select 'Turn on DEP for all programs and services except those I select:'.
    7. Click 'Add'.
    8. Browse for the application CRW32.exe. This file is located in:
    C:\Program Files\Business Objects\Crystal Reports 12\
    9. Select CRW32.exe and click 'Apply'.
    10. Click 'OK' to close the 'System Properties' dialog box.
    11. Log on as an Administrator and start Crystal Reports.
    Now try to export report to the text format and observe the behavior.
    Regards
    Girish Bhosale

  • Authorization Object is not working when report is modified.

    Hi BW Guru's
    We have Company Code as Authorization Object .and we have 3 company Codes (xxxx,yyyy,zzzz).where the users under Company code xxxx are not supposed to view company code yyyy,zzzz data etc.
    I modified an existing Report and transported to production.But the Authorization Object is not working for that report.The Report is defaultly displaying all the company codes data(xxxx,yyyy) for all the users.But for the other reports its(company code ) is working fine.
    What could be the problem?Is theproblem in transporting the objects.But i transported all the objects inluding auhorization object.
    Please send me the solution as it is very much urgent.
    The solution will be def. awarded with full points.
    Regards
    Sanjay

    hi Sanjay,
    please don't post the same question again, check and response back from your previous thread
    Re: Authorization Object is not working when report is Modified.
    hope this helps.
    would be nice if you reward for helpful answers to all of your previous postings, e.g
    docs related to RRI

  • Apex 3.2 hook javascripts to IR and execute those when report is refreshed

    Hi,
    You propably have see tricks to attache javascript to IR refresh using time out and gReport.l_LastFunction e.g. these.
    http://roelhartman.blogspot.com/2010/04/alternative-to-alternating-row-colors.html
    http://www.talkapex.com/2009/03/column-groups-in-apex-interactive.html
    Here is alternative solution:
    You need load jQuery 1.4.2 e.g. in page template header
    Create page zero if your application do not have one. Then create HTML region before footer with no template.
    Place code to region source
    <script type="text/javascript">
    ;(function($){
    $.htmldbIrBusyGrap=$.fn.htmldbIrBusyGrap=function(){
    /* for bind IR ajax */
    /* check do we have IR on page */
    if($('#apexir_WORKSHEET_REGION').length>0){
      /* replace apex internal function _BusyGraphic */
      gReport._BusyGraphic=function(pState){
       if(pState==1){
        /* ir ajax start trigger htmldbIrAjaxStart event and show loading icon */
        $.event.trigger('htmldbIrAjaxStart');
        $('#apexir_LOADER').show();
       }else{
        /* check is there data stored to #apexir_WORKSHEET */
        if(!$('#apexir_WORKSHEET').data('htmldb')){
          /* store data to #apexir_WORKSHEET */
          $('#apexir_WORKSHEET').data('htmldb',{irReady:true});
          /* trigger htmldbIrReady event */
          $.event.trigger('htmldbIrReady');
         /* hide loading icon and trigger htmldbIrAjaxEnd*/
         $('#apexir_LOADER').hide();
        $.event.trigger('htmldbIrAjaxEnd');
       return;
      $.event.trigger('htmldbIrReady');
    $.htmldbIrReady=$.fn.htmldbIrReady=function(fn){
    $(function(){
      if($.isFunction(fn)&&$('#apexir_WORKSHEET_REGION').length>0){
       $('#apexir_WORKSHEET_REGION').bind('htmldbIrReady',fn);
    })(jQuery);
    addLoadEvent(function(){$.htmldbIrBusyGrap();});
    </script>Now your IR will trigger htmldbIrReady event when report is refreshed.
    Usage example
    <script>
    $(function(){$('#foo').bind('htmldbIrReady',function(){alert('Hello');});});
    </script>Also it trigger htmldbIrAjaxStart and htmldbIrAjaxEnd events.
    Usage example
    <script>
    $(function(){$('#foo').bind('htmldbIrAjaxStart',function(){alert('Ajax start');});});
    $(function(){$('#foo').bind('htmldbIrAjaxEnd',function(){alert('Ajax end');});});
    </script>Or use function $.htmldbIrReady example
    <script>
    $(function(){$.htmldbIrReady(function(){alert('Hello');});});
    </script>Small demo that logs those events here
    http://actionet.homelinux.net/htmldb/f?p=100:87
    Hope this helps and you post other innovative solutions or usage examples about this
    Regards,
    Jari

    Jari,
    i have found my bug which prevented the Page from working.
    i have a custom build apex_loader
    <script src="#WORKSPACE_IMAGES#jquery-1.4.2.min.js" type="text/javascript"></script>
    <script src="#APP_IMAGES#jquery.simplemodal-1.3.5.js" type="text/javascript"></script>
    <script type="text/javascript">
    * @param pRegionStaticId ID of region to set to modal
    * @param pOptions Options for modal Screen. See: http://www.ericmmartin.com/projects/simplemodal/#options for more info
    goModal=function(pRegionStaticId, pOptions){
      var vDefaults = {persist: true, overlayCss: {backgroundColor: '#606060'}}; // Note: It's important that you leave the persist = true otherwise items values will be cleared
      pOptions = jQuery.extend(true,vDefaults, pOptions);
      // To maintain order of APEX items (see forum posting above)
      $('#' + pRegionStaticId).wrap('<div></div>');
      // toon het ajax laad scherm
      html_ShowElement('AjaxLoading');
      // Laat de region zien, in dit geval 'apexir_LOADER' --> het icoontje bovenin
      //  $('#' + pRegionStaticId).show();
      // Open het modal scherm
      //  $('#' + pRegionStaticId).modal(pOptions);
    }// goModal
    * Sluiten van het modal scherm
    modalClose=function(){
       // verberg het ajax laad scherm
       html_HideElement('AjaxLoading');
       $.modal.close();
    }// modalClose
    // OnLoad tasks
    $(document).ready(function(){
      // Voor alleen uit wanneer er een IR is op de pagina
      if ($('.apexir_WORKSHEET_DATA').length > 0) {
        // See apex_ns_3_1.js for _BusyGraphic
        function dispIRBusyGraphics(pState){
        if(pState == 1){
            // Here apexir_LOADER is the object ID.
            // You can use your own region if you wanted to etc...
         goModal('apexir_LOADER', {position:['30%',]});
        else{
           modalClose();
        return;
        }// dispIRBusyGraphics
        function updateIRJS(){
         // This time out is required since after the report is refreshed
         // via AJAX, need to reattach the l_LastFunction command
         setTimeout(
           function(){
            gReport._BusyGraphic = function(pState){dispIRBusyGraphics(pState);};
           1000
        gReport = new apex.worksheet.ws('');
        gReport.l_LastFunction = function(){dispIRColGroups();}
        // Need to put timeout since not registering on initialization
        setTimeout(function(){gReport._BusyGraphic = function(pState){dispIRBusyGraphics(pState);};},500);
        updateIRJS();
      } //If IR exist
    </script>and when i disabled this on page 0 the functionality was working correctly.
    Thanks for demoing this in the application.
    Marco

  • Dump while running a stock report for one year

    hi experts,
                        i'm getting  dump error while running a stock summary report for one year
            the error is as follows:
      A RAISE statement in the program "CL_GUI_CUSTOM_CONTAINER=======CP" raised the
       exception
      condition "CNTL_ERROR".
    regards,
    andrews.

    Hi Andrew,
    Did you try running the report for a smaller period of maybe a month. Check for any authorisation related issues.
    The dump has a lot of detailed and valuable information about the error. If feasible, post the dump data for further analysis.
    Regards,
    Pranav.
    Edited by: Pranav Mandelia on Sep 6, 2011 2:07 PM

  • When reporting "Spend" do you use PO Value, Invoice Amount or Goods Receipt

    When reporting "Spend" do you use PO Value, Invoice Amount or Goods Receipt? I am trying to standardize reporting and would like feedback on what is the norm. The users cannot agree so I need to know what the standard is.

    PO Value is what is budgeted for ,
    Invoice is what is actually being paid for.
    GR would give you the value of goods received. My take on this is that it should be Invoice value since this is what is reflected in the books and is actually being paid for...

  • Date not showed when report is viewed in PDF .

    Hi,
    We have a text field that shows the date on which the report is running.Date is not showed when report is viewed in PDF.But in HTML we can view them . Can any one help me out?
    Totally there are four pages for the report.

    I have observed the PDF driver iin EPM 11.1.2.x is not up-to-date and technically the Date (Text) is there just like in HTML. However, when you increase the View (Zoom in), it eventually does show up.
    I have chatted with Oracle Support, and they will not address it with a patch for now.

  • Slow performance of report with Cal year

    Experts,
      Hope all is OK . We have  BW appraisal reports, one of which is Appraisal markings by grade report having Calendar year as selection variable.
    If I run this report with calendar year as selection parameter , this reports is taking very very long time and is not doing any thing .
    If I remove Calendar year in the report, then the report is executing in a reasonable amount of time.
    But we need calendar year as a variable in the report. Please help me why with this variable taking very long time ?
    I appreciate any advice.
    Thanks

    Hello Manoj,
    Take into consideration creating a aggregate on Calyear.
    Your problem is because of  variable usage, your problem is data selection of calyear. If you create and aggregation on this cube by Calyear, selection will be very fast.
    Sarhan.

  • Use same database logon as when report is run

    Is there a way to set the option for "When viewing report" to "Use same database logon as when report is run" for all reports?

    If scheduling we have schedule manager in XIR2 which will do a folder at a time, it's been added to the CMC in 3.x I believe.
    For running the reports I think you would need to use the [SDK|/community [original link is broken]; if if you wanted to modify a bunch of reports at the same time, or use the publishing wizard to publish a bunch of them (no use if the reports are already uploaded)
    Regards,
    Tim

  • How to improve query performance when reporting on ods object?

    Hi,
    Can anybody give me the answer, how to improve my query performance when reporting on ODS object?
    Thanks in advance,
    Ravi Alakuntla.

    Hi Ravi,
    Check these links which may cater your requirement,
    Re: performance issues of ODS
    Which criteria to follow to pick InfoObj. as secondary index of ODS?
    PDF on BW performance tuning,
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/cccad390-0201-0010-5093-fd9ec8157802
    Regards,
    Mani.

Maybe you are looking for

  • Samsung 4g lte wifi keeps disconnecting when computer in sleeep mode?

    I just purchsed this product and whenever I put my computer to sleep within either minutes or hours the power is still on but nothing else is lit on my samsung 4glte. Is there something I should do so it is in standby for whenever I open my computer

  • Creating new Positions using RH_CREATE_POSITIONS?

    Hi I tried to use the RFC rh_create_positions to create new positions using C#. But i get an error:"Screen output without connection to user". Well is there any work around for it or is there any other RFC/BAPI i can use to create positions under an

  • How do I remove iTunes U from my Mac?

    How do I remove iTunes U from my Mac?  Or permanently remove files from iTunes U? I made the mistake and added my own local files to iTunes U.  I deleted them from iTunes U.  Now when I add the files back into iTunes, it places them in iTunes U. Than

  • Install Leopard on Tiger MBP using Restore Disk from Leopard MBP

    As the title suggests, I just bought a new Leopard MBP which, of course, comes with the restore disks. I tried to install Leopard on my old MBP using those disks and it says "This software can not be installed on this machine." I thought as long as i

  • Problem when turn on mini Ipad.

    I have problem when turn on mini ipad. I have to slice the unlock after it flashing 3 times and not after flashing5 times!! After the unlock flashing 5 times it will turn off the screen and I have to push any button on my ipad mini to activate the sc