DAte comparison hampering query??

Hi,
I have the following query which is taking 17 seconds to retreive 10 records if date range spans more than 12 months. The explain plan is given below:
SELECT trunc(calendar_date,'MM'),sum(man_days_demand)
FROM (
SELECT TRUNC(cal.calendar_date) calendar_date,
(-- in line column qry to count the service reqs falling on that specific day
SELECT nvl(sum(count(ssrj.assigned_field_service_rep)),0)
FROM sop_service_request_job ssrj, sop_service_request ssr
WHERE (((cal.calendar_date between ssrj.scheduled_start_date AND
get_end_date(ssrj.scheduled_start_date,
ssrj.expected_service_hours,
ssrj.weekend)))
OR
(cal.calendar_date < ssrj.scheduled_start_date and
cal.calendar_date > get_end_date(ssrj.scheduled_start_date,
ssrj.expected_service_hours,
ssrj.weekend)))
and ssrj.service_request_id = ssr.service_request_id
and ssrj.assigned_field_service_rep is not null
and trunc(calendar_date,'MM') = trunc(cal.calendar_date,'MM')
group by cal.calendar_date
) Man_Days_demand
FROM sop_fiscal_calendar_v cal, sop_service_user ssu, sop_service_request ssr,
sop_service_request_job ssrj, CSA_PLATFORM_MASTER cpm
WHERE
trunc(calendar_date,'MM') between trunc(to_date('&date_range_start_date','mm/dd/yyyy'),'MM')
AND trunc(to_date('&date_range_end_date','mm/dd/yyyy'),'MM')
and ssu.sso_id = ssrj.assigned_field_service_rep
and ssrj.service_request_id = ssr.service_request_id
GROUP BY calendar_date
GROUP BY trunc(calendar_date,'MM')
SELECT STATEMENT, GOAL = CHOOSE
SORT GROUP BY
  VIEW
   SORT GROUP BY
    FILTER
     NESTED LOOPS
      HASH JOIN
       TABLE ACCESS FULL
       MERGE JOIN CARTESIAN
        MERGE JOIN CARTESIAN
         INDEX FAST FULL SCAN
         BUFFER SORT
          INDEX FULL SCAN
        BUFFER SORT
         INDEX FULL SCAN
      INDEX UNIQUE SCANThe above query returns sum of demand for each month.
How can i tune this query to perform faster?
Thanks,
JP

Maybe rethink your TRUNC statements?
One condition in your SELECT statement is:
trunc(calendar_date,'MM') between trunc(to_date('&date_range_start_date','mm/dd/yyyy'),'MM')
AND trunc(to_date('&date_range_end_date','mm/dd/yyyy'),'MM')
You could change that to_
calendar_date BETWEEN TRUNC(TO_DATE('&date_range_start_date', 'mm/dd/yyyy'), 'MM')
                  AND ADD_MONTHS(TRUNC(TO_DATE('&date_range_end_date','mm/dd/yyyy'), 'MM'), 1)
not tested
C.

Similar Messages

  • Query about date comparison

    Hi,
    I have a database table with a date field called 'ENDDAT'
    How do I write a select query that selects all records whose difference between sy-datum and 'ENDDAT' is greater than 7.
    If I do the normal date comparison for eg.
    select * from <databasetable> where enddat - sy-datum > 7
    or
    select * from <databasetable> where (enddat - sy-datum) > 7
    It throws error that '-' is not a valid comparison operator.
    Can anyone help????

    I've never seen that done before.  You can do as joseph has suggested.   If you can do it in the select statement, I'm not really sure that you'd want to put that kind of processing on the database.
    data: begin of itab occurs 0,
          enddat type sy-datum,
          end of itab.
    select * into corresponding fields of table itab
           from <databasetable> .
    data: cdatum type sy-datum.
    Loop at itab.
    cdatum = enddat - sy-datum
    * if <= 7, then delete from itab.
    if cdatum <= 7.
    delete itab.
    endif.
    endloop.
    Regard,
    Rich Heilman

  • OBIEE Date Comparison report with multiple measures

    Hello everyone...
    I have a requirement where I need to create a date comparison report (Current Month vs. Prior Month vs Prior Month Year Ago vs YTD vs Prior YTD vs Rolling 3 months, etc) with multiple Measures (Quote count, Quote offered count, New Business count, etc). I am to generate this report in this fashion:
    Quotes Current Month vs PM vs YoY Prior
    Month Current Month Prior Year Current
    YTD vs PM Prior
    YTD Rolling 3 Months vs PM Prior Rolling 3 Months
    Issued 120 120 123 1400 1020 1700 1580
    Unique Risks
    Offered 556 449 571 5881 6220 6101 5892
    Unique Risk Close Ratio
    Offered Close Ratio 21.6% 26.7% 21.5% 23.8% 16.4% 27.9% 26.8%
    Bitmap
    Avg Issued Premium 240 238 222 2801 2630 3104 2892
    Avg Offered Premium
    New Business
    Count
    Avg Full Term Premium
    I understand that time series is an option, and have created the time series (which show up as measures).
    My problem is:
    when creating the report (even as a pivot table) , OBIEE is not allowing me to drag the measure to rows, nor is it allowing me to drag the time series to columns. Also, I need to do conditional formating on some of the columns showing an up arrow for increased vs. prior month and down arrow for decreased vs. prior month.
    Does anyone have a solution for this issue? Any assistance would be greatly appreciated...
    Please advise and thanks!!!

    Jason,
        You've been very helpful, but I guess I'm just not explaining myself that well. The Credit Memo's throw things off because they do not contain a "Paid Date" value. That field in the record is blank. Since it is blank the report query ignores them. Therefore when the report query returns all records that have a "Paid date" range of "x to y" they are never returned. This is a problem whenever a credit memo exists for an invoice because the "invoice total" never changes. So when a customer pays on their account for a particular invoice, they only pay what is due which is the "invoice total" minus any "credit" from the "Credit Memo". So when my A/R person receives payment they are showing the invoice paid in full because MAS automatically includes all invoices and credit memo's. My report does not because there is no data in the "Paid Date" field of the record for Credit Memos.
    I've been doing alot research in trying to resolve this "exception" to my report. I think I may be on to something, but my knowledge of arrays is extremely limited. My resolution involves populating an array with the "invoice numbers" that are returned from the initial query from the supplied date range. Then using the "invoice numbers" from the array have it then populate my details section of the report with all of "invoice records" both the actual invoice record and any "credit memo" records. I can then group the records returned  based upon the "invoice number". then within that grouping I can performing my calculations to show whether or not the invoice has been paid in full. What do you think?  I've been able to populate an array with the invoice numbers based upon my date search range, but I have yet to figure out how to take that information and perform another lookup to pull in the rest of the data I need. Do you have any ideas?
    Thanks.  Bill

  • How to match time alone (without date) in a query

    Hi, I have a date colum named timeprop, where a time value has been inserted through:
    DateFormat.getTimeInstance(DateFormat.MEDIUM, "de_DE").parse("11:12:13")
    In SQL developer I can check the inserted value as:
    select timeprop from version_table where timeprop is not null;
    getting:
    TIMEPROP
    01.01.1900 11:12:13
    so I guess Oracle added a default date as 1.01.1900. Ok.
    But if I run:
    select timeprop from version_table where timeprop = to_date('11:12:13', 'hh24:mi:ss');
    then I get no result. I succeed only after adding that default date to the query - by patching the format as well - e.g.
    select timeprop from version_table where timeprop = to_date('1.01.1900 11:12:13', 'dd.mm.yyyy hh24:mi:ss');
    Basically, no time alone in a query.
    Is this transformation always needed or am I missing anything from this game ?
    Server is 11gr1.
    Thanks.

    sperkmandl wrote:
    Hi, I have a date colum named timeprop, where a time value has been inserted through:
    DateFormat.getTimeInstance(DateFormat.MEDIUM, "de_DE").parse("11:12:13")I can only suppose that means that you are not using setTime().
    >
    In SQL developer I can check the inserted value as:
    select timeprop from version_table where timeprop is not null;
    If you database is NOT Oracle then now would be the time to state that.
    > Is this transformation always needed or am I missing anything from this game ?
    The data type in the database DDL is relevant.
    Oracle doesn't have any time only data types.
    So if and only if you (and everyone else) has inserted time values in a consistent manner then you could use normal comparison by using setTime().
    If that isn't true then you must craft Oracle PL/SQL to remove the time part of the timestamp values before you do your comparisions.

  • Doubt regarding Date Comparison

    Hello,
    i am facing a problem in date comparison
    SELECT max(l.id)
    FROM irf_bill_details l
    WHERE to_char(l.agreement_id) = '508814'
    AND l.billing_client_id = 'BHPIF'
    AND extract(YEAR FROM l.bill_date) < extract(YEAR FROM to_date('01-Jan-2010', 'dd-Mon-yyyy'))
    So when i am using this Query m getting the result ...BUT ...
    When i use the Below Query .... i am getting NULL ... So the problem surely is in when comparing with months ..?? how to get rid
    SELECT max(l.id)
    FROM irf_bill_details l
    WHERE to_char(l.agreement_id) = '508814'
    AND l.billing_client_id = 'BHPIF'
    AND extract(YEAR FROM l.bill_date) < extract(YEAR FROM to_date('01-Jan-2010', 'dd-Mon-yyyy'))
    AND extract(MONTH FROM l.bill_date)||'-'||extract(YEAR FROM l.bill_date) < extract(MONTH FROM to_date('01-Jan-2010', 'dd-Mon-yyyy'))||'-'||extract(YEAR FROM to_date('01-Jan-2010', 'dd-Mon-yyyy'))
    --------------------------------------------------------------------------------------

    Aijaz Mallick wrote:
    Hello,
    i am facing a problem in date comparison
    SELECT max(l.id)
    FROM irf_bill_details l
    WHERE to_char(l.agreement_id) = '508814'
    AND l.billing_client_id = 'BHPIF'
    AND extract(YEAR FROM l.bill_date) < extract(YEAR FROM to_date('01-Jan-2010', 'dd-Mon-yyyy'))
    So when i am using this Query m getting the result ...BUT ...
    When i use the Below Query .... i am getting NULL ... So the problem surely is in when comparing with months ..?? how to get ridAre you saying that you're still getting one row of output, but the id on the row is NULL?
    SELECT max(l.id)
    FROM irf_bill_details l
    WHERE to_char(l.agreement_id) = '508814'
    AND l.billing_client_id = 'BHPIF'
    AND extract(YEAR FROM l.bill_date) < extract(YEAR FROM to_date('01-Jan-2010', 'dd-Mon-yyyy'))
    AND extract(MONTH FROM l.bill_date)||'-'||extract(YEAR FROM l.bill_date) < extract(MONTH FROM to_date('01-Jan-2010', 'dd-Mon-yyyy'))||'-'||extract(YEAR FROM to_date('01-Jan-2010', 'dd-Mon-yyyy'))
    --------------------------------------------------------------------------------------Whenever you have a problem, post some sampel data (CREATE TABLE and INSERT statements) and the results you want from that data. Explain how you get those results from that data.
    As long as I don't know where you're starting from (sample data) or where you want to go (results) it's hard for me to give you good diorections.
    I suspect you want to be using TRUNC rather than EXTRACT, if not a plain DATE comparison.
    For example, if you have a string p_cutoff_date (such as '01-Jan-2010', but not necessaily the 1st of the month) and you want to see if l.bill_date is earlier than the beginning of the month that contains p_cutoff_date, then:
    WHERE   l.bill_date < TRUNC ( TO_DATE ( p_cutoff_date
                                          , 'dd-Mon-yyyy'
                       , 'MONTH'
                       )As you said in the subject line, you're trying to compare DATEs. So compare DATEs: don't convert them to NUMBERS (using EXTRACT) and then to strings (using ||); keep the DATEs as DATEs.

  • Unable to access the data from Data Management Gateway: Query timeout expired

    Hi,
    Since 2-3 days the data refresh is failing on our PowerBI site. I checked below:
    1. The gateway is in running status.
    2. Data source is also in ready status and test connection worked fine too.
    3. Below is the error in System Health -
    Failed to refresh the data source. An internal service error has occurred. Retry the operation at a later time. If the problem persists, contact Microsoft support for further assistance.        
    Error code: 4025
    4. Below is the error in Event Viewer.
    Unable to access the data from Data Management Gateway: Query timeout expired. Please check 1) whether the data source is available 2) whether the gateway on-premises service is running using Windows Event Logs.
    5. This is the correlational id for latest refresh failure
    is
    f9030dd8-af4c-4225-8674-50ce85a770d0
    6.
    Refresh History error is –
    Errors in the high-level relational engine. The following exception occurred while the managed IDataReader interface was being used: The operation has timed out. Errors in the high-level relational engine. The following exception occurred while the
    managed IDataReader interface was being used: Query timeout expired. 
    Any idea what could have went wrong suddenly, everything was working fine from last 1 month.
    Thanks,
    Richa

    Never mind, figured out there was a lock on SQL table which caused all the problems. Once I released the lock it PowerPivot refresh started working fine.
    Thanks.

  • Can we use session variables in BI publisher's Data Model SQL Query?

    Hi Experts,
    We need to implement Data level security in BI Publisher 11g.
    In OBIEE we do so by using session variables, so just wanted to ask if we can use the same session variables in BI Publisher as well
    ie can we include the where clause in the Data Models SQL Query like
    Where ORG_ID = @{biServer.variables['NQ_SESSION.INV_ORG']}
    Let me know your views on this.
    PS: We are implementing EBS r12 security in BI Publisher.
    Thanks

    Read this -> OBIEE 11g: Error: "[nQSError: 23006] The session variable, NQ_SESSION.LAN_INT, has no value definition." when Creating a SQL Query using the session variable NQ_SESSION.LAN_INT in BI Publisher [ID 1511676.1]
    Follow the ER - BUG:13607750 - NEED TO BE ABLE TO SET A SESSION VARIABLE IN OBIEE AND USE IT IN BI PUBLISHER
    HTH,
    SVS

  • SAP MII 14.0 SP5 Patch 11 - Error has occurred while processing data stream Dynamic Query role is not assigned to the Data Server

    Hello All,
    We are using a two tier architecture.
    Our Corp server calls the refinery server.
    Our CORP MII server uses user id abc_user to connect to the refinery data server.
    The user id abc_user has the SAP_xMII_Dynamic_Query role.
    The data server also has the checkbox for allow dynamic query enabled.
    But we are still getting the following error
    Error has occurred while processing data stream
    Dynamic Query role is not assigned to the Data Server; Use query template
    Once we add the SAP_xMII_Dynamic_Query role to the data server everything works fine. Is this feature by design ?
    Thanks,
    Kiran

    Thanks Anushree !!
    I thought that just adding the role to the user and enabling the dynamic query checkbox on the data server should work.
    But we even needed to add the role to the data server.
    Thanks,
    Kiran

  • No data from BW-Query in BO-tools

    Hello all
    On a newly installed BO XI 3.1 with the SAP integration kit I cannot get data from my existing BW queries.
    For example, if I start Xcelsius and add my BW-system as connection I can get the structure of the query (headings) but no data is displayed, neither in the connection's preview tab nor in the web preview.
    The same happens if I create a QaaWS on this BW-query - I see the query headings, but not the actual data.
    The query shows data if I open it directly in my web browser and it's a really simple one: no variables, no extras, only a few columns and rows.
    I use SAP BW 7.01 SP6, XI 3.1 12.3.3 and XCelsius 2008 5.3.4
    In SAP BW my user has SAP_ALL as well as BOE Admin & Content producer roles.
    I'm relatively new to BO products so I have no idea where to start looking for the cause. Please help!
    BR
    Kanan

    Hi
    After I found the document "Using Xcelsius 2008 with SAP NetWeaver BW" (http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/10ad2489-8956-2d10-f8ab-ed4cce2766da?quicklink=index&overridelayout=true) and followed the steps it works.
    It seems as if the error was not in the system but in front of it - a typical case of RTFM, although the manuals are not always easy to find.
    sorry & thanks.
    BR
    Kanan

  • Key date for a query

    Dear All,
    I have created a customer exit variable on key date of a query.
    With this input variable i am first asking user to input one particular date say he enters 31.12.2010 then i am trying to add 1 more day to it and making it 01.01.2011.
    I have put a break point in the code but it does not stop the processing there.. report executes directly taking the first user input.
    I want to add 1 more day to the user entered date and this modifiied date should be the input date for key date field.
    Below is my code.
      WHEN 'ZCAL_DAY_EXT'.
        IF I_STEP = 2. "after the popup
          LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE
          WHERE VNAM = 'ZCAL_DAY_EXT'.
            CLEAR L_S_RANGE.
          ENDLOOP.
          DATA: v_temp like sy-datum.
          v_temp = loc_var_range-low.
          v_temp = v_temp + 1.
          L_S_RANGE-LOW = v_temp.
          L_S_RANGE-SIGN = 'I'.
          L_S_RANGE-OPT = 'EQ'.
          APPEND L_S_RANGE TO E_T_RANGE.
        ENDIF.
    Do let me know where am i going wrong? Or is it we cannot use customer exit with Key date.
    Thanks & Regards,
    Anup
    Edited by: Anup Chaudhari on Aug 2, 2011 7:16 AM

    Hi Anup,
    Basically I_STEP = 1 is used for populating the default value which will be shown on selection screen and I_STEP = 2 is the step in which you does the processing on variable values which are entered on selection screen.
    I am surprised that your internal table is empty, actually it is supposed to contain all the variable values which are entered in I_STEP = 1.
    Can you try to add some more variables along with the current variable and check whether their value is coming in the internal table or not?
    Finally what you can try is get the user input date in one variable and then create another customer exit variable in which you will calculate the new value and use this variable in Key date, the problem might be that we are trying to modify the same variable, actually it should not be the problem but I have no clue what is happening and you can just try this alternative.
    Regards,
    Durgesh.

  • Oracle Forms - How can I create a Data Block with query

    Dear friends I have a question, I couldn't do this..
    I have a sql query, I want to show the datas of the query.. How can I do this. ?
    Data Block Wizard wants a table, view or stored procedure, but I have a query, how can I create a data block with my query.. I m waiting your helps..? Please...
    Semih

    Hi,
    You have two options
    1. create a view and base the block on the view
    2. create a block with a query Data Source Type of 'FROM clause query'
    Hope this helps
    Neil

  • "Source not found" Error creating URL Data control with query parameters

    Hi,
    I have a restful service for which i want to create a URL data control. I am able to create the URL data control successfully when i am not passing any parameters in the Source field. But if i am specifying the parameters in the source field like this Department=##ParamName##, something weird is happening. After giving the param string in the Source field, it asks for default param value to test the url. It tests the url successfully. After that i select XML as the data format in which i am mentioning the xsd like this . "file:///C:/..../something.xsd" . And this is when i am getting the error. "Invalid Connection. The source is not found". I am giving exactly same path for xsd which i gave while creating URL data control without query parameters. Infact i was able to create the URL data control with query parameters successfully till afternoon. after that it started giving me this error all of a sudden. Infact as soon as i was able to create a URL data contol with query parameter successfully, i took a backup of the application before moving further. But even that backup is not working now.
    As far as i understand, i dont think there will be any change in xsd if query params are passed to a web service. Please correct me if i am wrong.
    Just dont know what could be the issue. Please help
    Thanks

    Hi,
    xsd is used for the URL service to know what the returned data structure is so it can create the ADF DC metadata
    Frank

  • Where to get BW Metadata: owner, creation date, change date of a query / WS

    Hello,
    I need a report over the existing queries / worksheets and the owner, creation date, change date of a query etc.
    You see some of the information when you go over query properties in the query designer. But you see only the information of one (the opened) query. And you have to do this for every query ...
    My idea is to go over BW Metadata in the technical content.
    Here is the cube BW Metadata 0BWTC_C08
    (The InfoCube BW Statistics u2013 Metadata contains metadata from the Metadata Repository.)
    Is this the way to do it? Or any other suggestions u2026
    Can I get infos about used structures , etc over this way
    Thanks Markus

    I had to work on an other subject:
    But now the source of information is clear:
    RSRREPDIR - index of all queries
    RSZELTDIR -  index of all queries-components
    RSRWORKBOOK - Verwendungsnachweis für Berichte in Workbooks
    RSRWBINDEX - List of binary large objects (Excel workbooks)
    RSRWBINDEXT - Titles of binary objects (Excel workbooks) in InfoCatalog
    The tables are to join over
    RSRREPDIR.COMPUID  = RSZELTDIR.ELTUID
    RSZELTDIR.TEXTLG  contains the description
    RSRWORKBOOK.GENUID  = RSRREPDIR.GENUID
    RSRWBINDEXT and RSRWBINDEX are connected over WORKBOOKID
    I'd like to put the information of all of this tables in a cube and define a query on it.
    I have to define new datasource, infosource to get the data in the cube.
    Right?
    Now i see some existing datasource objects in the technical content.
    0TCTQUERID, 0TCTQUERID_TEXT, 0TCTQUERY, 0TCTQUERY_TEXT
    I can't open them to look in. But they might be helpfull. Anybody used them?
    Markus

  • Problem with different resultset with same data and same query in Oracle 8.1.7 and 9i

    Hello,
    I have been using this query in oracle 8.1.7
    SELECT
    ID,
    AREA_NO
    FROM MANAGER_AREA MGR
    WHERE COMPANY_ID = :id AND
    (:value < (SELECT COUNT(ROWID)
    FROM MANAGER_WORK MW
    WHERE MW.AREA_ID = MGR.ID AND
    (MW.END_WORK IS NULL OR MW.END_WORK >= SYSDATE)))
    order by AREA_NO;
    In the above query I want to see rows from MANAGER_AREA table depending upon date criteria in the table MANAGER_WORK and also upon the parameter :value i.e if I pass a value as 0 I get to see records for which their is atleast 1 record in MANAGER_WORK with the date criteria and if I pass -1 then I get all the records because minimum value that count(*) would give is 0. The resultset was as expected in 8.1.7.
    A couple of days back I installed PERSONAL 9i to test for testing the basic functionality of our program with the same data. This query fails and irrespective whether I pass -1 or 0 it returns me same dataset which I would have got in case if I pass 0.
    I do not know whether this is a bug that has got introduced in 9i. Can anybody help me with this problem. It would be difficult for me to change the parameter send to this query as the Query is called from many different places.
    Thanks in advance
    Amol.

    I cannot use a Group by and a having statement over here. The problem with 'Group by' and 'having' clause is If I have to make a join between the two tables. When I use join then I get only rows that are linked to each other in the table.
    If I use outer join to solve that problem then I have to take in consideration the other date condition. My previous query use to virtually discard the corelated query result by using -1 as the value. This will not happen in the join query.
    Amol.

  • Execution date in a query

    Hello all,
    Is there any way to use sy-datum or something like that to store execution date of a query?
    Thanks in advance
    Carmen

    Hi Carmen,
    could you please clarify what do you want to achieve?
    - Do you want to store somewhere when a particular query has been executed?
    - Do you want to execute a query with a filter on SY-DATUM?
    As a first input, on the global properties on a query, you have the query keydate, which is by default SY-DATUM
    hope that helps
    Olivier.

Maybe you are looking for

  • How can I reset password in email application

    I'm helping an elderly neighbour (I'm elderly myself) with an email problem on his Mac (I don't know which one, but this is a pure S/W problem). When he starts his system, he eventually gets a prompt for his SMPT password. Nothing works. He can signo

  • MacBook won't go to sleep

    I have issues putting my macbook to sleep in this configuration: 1. lid closed 2. connected to an external LCD monitor (via VGA adaptor) 3. power adaptor attached (100% Charged) 4. external keyboard and mouse (via USB) Ive tried all the suggestions i

  • ITunes 7.1.1.5 will not play audio from inserted cd

    I have been experiencing an issue with iTunes on my PC. It will not play any audio from inserted discs. This includes burned discs and commercial discs. When I attempt to play the music the song will stay highlighted briefly, about 2 sec., and then i

  • Horizontal Scroll bar in a list Box?

    Hi, I have a requirement in Adobe Designer where my List Box should also show Horizontal Scroll bar in it. Is it possible? Thanks.

  • Adobe Flash 9 Active X

    I really need Adobe Flash 9 Active X, but when I try to install it, error message shows up. I uninstalled newest adobe flash 11, but stil no results. Help me please, what should I do?