Execution time of query with high variance

I have an Oracle Database 11.2 R2 which is set up just for testing purposes, so there is no other activity except mine. Now I have a query which I ran 10 times in a row. Between the executions I always flushed BUFFER_CACHE and SHARED_POOL. The strange thing is, that the execution time of the query is strongly varying from 13 seconds up to 207 seconds. From the 10 executions I have 4 times <25 seconds and 4 times > 120 seconds.
What could be the reason for this? As I've said, there is no other activity on the database and it is always the same query with the same parameters running on the same set of data.
The background to this is that I would like to compare the execution time of exactly the same query with different database settings. So I thought I could just run the query ten times and use the average but I didn't expect such a high variance.
Kind regards
Peter

Hi,
for each execution, look at:
1) plan hash value
2) total logical I/O
3) physical I/O
That should give you some clues as to what's going on.
Best regards,
Nikolay

Similar Messages

  • Execution time of query on different indexes

    Hello,
    I have a query on the table, the execution time has hugh difference using different indexes on the table. The table has about 200,000 rows. Any explaination on it?
    Thanks,
    create table TB_test
    ( A1 number(9),
    A2 number(9)
    select count(*) from TB_test
    where A1=123 and A2=456;
    A. With index IDX_test on column A1:
    Create index IDX_test on TB_test(A1);
    Explain plan:
    SELECT STATEMENT
    Cost: 3,100
    SORT AGGREGATE
    Bytes: 38 Cardinality: 1
    TABLE ACCESS BY INDEX ROWID TABLE TB_test
    Cost: 3,100 Bytes: 36 Cardinality: 1
    INDEX RANGE SCAN INDEX IDX_test
    Cost: 40 Cardinality: 21,271
    Execution time is : 5 Minutes
    B. With index IDX_test on column A1 and A2:
    Create index IDX_test on TB_test(A1, A2);
    Explain plan:
    SELECT STATMENT
    Cost: 3 Bytes: 37 Cardinality: 1
    SORT AGGREGATE
    Bytes: 37 Cardinality: 1
    INDEX RANGE SCAN INDEZ IDX_test
    Cost: 3 Bytes 37 Cardinality:1
    Execution time is: 1.5 Seconds

    Additional you should check how many values you have in your table for the specific column values.
    The following select might be helful for that.
    select count(*)  "total_count"
           ,count(case when A1=123 then 1 end) "A1_count"
           ,count(case when A1=123 and A2=456 then 1 end) "A1andA2_count"
    from TB_test;Share your output of this.
    I expect the value for A1_count still to be high. But the value for A1+A2_count relatively low.
    However 5 minutes is far to long for such a small table. Even if you run it on a laptop.
    There must be a reason why it is that slow.
    First thing to consider would be to update your statistics for the table and the index.
    Second thing could be that the table is very sparsly fillled. Meaning, if you frequently delete records from this table and load new data using APPEND hint, then the table will grow, because the free space from the deletes is never reused. Any table access in the execution plan, will be slower then needed.
    A similar thing can happen, if many updates on previously empty columns are made on a table (row chaining problem).
    So if you explain a little, how this table is filled and used, we could recognize a typical pattern that leads to performance issues.
    Edited by: Sven W. on Nov 28, 2012 5:54 PM

  • Many execution of a query with different selections in the same work book

    Hi all,
    I have a workbook with one query that show sales of a plant. User can select many plants, but he doesn't like it, too easy. In this way query shows all the plant in the same sheet and he want a sheet for each plant.
    The most simply way to do this is making a query for each plant with a filter with the plant as a constant. Then I put all that queries in the workbook. But this is not too smart, right?
    Any suggestion?

    Hi,
        I will try and explain here, if you get stuck and do get back.
    1) On Sheet1 Rename it to BEX01 and Add the Query that will return all Plants. Hide this Sheet
    2) On Sheet2 Rename it to BEX02 and Add the Main Query. Hide this Sheet.
    3) On Sheet3 Rename it to Main and Add a Command Button. Goto Properties and Change the Name to cmdRefresh and then do View Code and add following code. 
    Private Sub cmdRefresh_Click()
               Call RefreshReports
    End Sub
    4) Add a Module to your VBA Project
    5) Open Module1 and Add following code.
    Option Explicit
    Public Sub RefreshReports()
        Dim wksBEX01 As Worksheet, wksBEX02 As Worksheet, wks As Worksheet
        Dim lRows As Long, lRow As Long
        Dim sPlant As String, sName As String
        Dim fRng As Range
        sName = "Main"
        With ThisWorkbook
            Set wksBEX01 = .Sheets("BEX01")
            Set wksBEX02 = .Sheets("BEX02")
        End With
        wksBEX01.Activate
        wksBEX01.Range("A1").Select
        'This will refresh both the Queries All Plants and the Main one.
        If Run("SAPBEX.XLA!SAPBEXrefresh", True) <> 0 Then
            MsgBox "Refresh of All Queries Failed."
            Exit Sub
        End If
        'Lets say your All Plants Query, Lists all the Plants Starting in Cell A15
        'Then Do the following.
        lRows = wksBEX01.Cells(Rows.Count, 1).End(xlUp).Row
        For lRow = 15 To lRows
            sPlant = Trim$(wksBEX01.Cells(lRow, 1).Value)
            'Now Use this Plant to Set the Filter Value for the Main Query.
            'I am assuming that your Plant Charateristic will show up in A14 on the Worksheet.
            With wksBEX02
                .Activate
                'Adjust this according to where you insert the Query and which cell has correct info.
                .Range("A14").Select
                Set fRng = Selection
            End With
            'Call the API to Do a Select Filter Value.
            If Run("SAPBEX.XLA!SAPBEXSetFilterValue", sPlant, "", fRng) <> 0 Then
                MsgBox "Unble to Set Filter for Plant : " & sPlant
                Exit Sub
            Else
                'Here you can Now Copy the the Sheet to new Sheet. If filter value worked.
                 Set wks = ThisWorkbook.Sheets.Add(After:=sName)
                 wksBEX02.Cells.Select
                 wksBEX02.Copy
                 wks.Range("A1").Paste
                 wks.Name = sPlant
                 sName = sPlant
            End If
        Next
         'Save the workbook as new name else you will have to first delete all the old sheets.    
         Thisworkbook.SaveAs "Some New Name"
    End Sub
    Here I have just created a new Sheet for Each Plant. You can work on the EXCEL Part to take and do what you want with new Sheets.
    Hope this gets you started.
    Just a Suggestion. Don't hide the BEX01 and BEX02 sheets untill the code works correctly.
    Datta

  • SSIS execution via sql query with dtexec utility by passing proxy account

    Hi, 
    i am executing ssis package with dtexec utility, with xp_cmdshell
    package is not a file based, but stored in sql/msdb
    while executing i am getting 'authentication failed'
    i haved tried with sa user and password, by passing it...but no luck
    so finally i want to authenticate it via proxy account, because same happen in sql agent job also but after creating proxy account it worked.
    please suggest me way to pass proxy account in query....i have used many combination like
    SET @SQLQuery = 'DTExec /SQL ^"\DataTransfer.dtx^" '
    SET @SQLQuery = @SQLQuery + ' /SET \Package.Variables[ServerName].Value;^"'+ @ServerName + '^" '
    EXEC master..xp_cmdshell @SQLQuery

    Have the EXEC master..xp_cmdshell run a batch instead that inside it it has a run as DOS command that runs the package with DTExec
    Arthur My Blog

  • SSIS execution time vs Query Analyser

    Hello there, I'm getting 2 contradicting results when executing a query from
    a) SSIS package
    b) Query Analyser
    SSIS package seems to take forever where as the QA does the job in 5 secs.
    I'd really appreciate your feedback.
    Thanks,
    Vivek

    yes. Here is the query
    ====================================
    select * 
    from W 
    where (DATEADD(yy, -21, GETDATE())) <= DOB and 
    REM is NULL and CoverageGrp not in ('C13') and 
     O_RID NOT IN
       select O_RID 
       from W 
       where CoverageGrp in ('C13')
      ) and 
     O_RID not in
       select DQO_RID from dbo.DRLoad
       where DQP_Id = '776'
    order by O_RID
    ======================================

  • Workbook Execution time...

    Hi friends
    i have one report which takes more than 20 mins. query can give o/p of 50000 rows. now tell how i can reduce the execution time. my query is well tuned. and giving minimum cost. but still in discoverer it takes 20 min. can u tell me how i can reduce the execution time(it should be executed 2-3 mins . should i go for high configuration PC?
    thanx.....

    Hi,
    You need to establish where the report is waiting to complete. If the report is waiting for the database query to finish then tuning the database query will improve performance. If the you are using Discoverer Desktop or Plus then you may be waiting for the PC to sort and format the results and so upgrading the PC will help, or if you are using Discovere Plus or Viewer you may be waiting for the Application Server to process the report so tuning the Application server may improve the timings.
    You say "my query is well tuned. and giving minimum cost". The cost of the query tells you nothing. You need to examine the query execution plan and benchmark the query before to determine the optimum query plan.
    Rod West

  • Getting estimated execution time via JDBC

    Hi,
    I have a web application that's meant to query by multiple search criteria, so queries can quickly become too complex. I know that using Resource Manager it is possible to prevent certain queries from running, based on estimated execution time.
    Is there any way to query these time estimates, making them available to the calling application? (before going ahead with execution)
    Thanks
    Ivan

    I am not sure if this is possible in JDBC, the best thing you can do is, get an average execution time for query and use in your application OR do a start time and end time while you are executing the scripts and get the difference.

  • How to find the Executed time of query

    hi,
       i want to find out the execution time of query like a sales report executed in 10 min. how to find out that? is there is any TC for that or what is the option to use that?
    and how to fing out execution time of Data source to info providers.. or DSOs to IC? like how much time taken to load data?
    regards,
    preety

    Hello Preety,
          Goto RSRT give the query name and see the technical property you will find the query generation time.
    For the time taken for execution Select the execute and debug mode in the options select display statistics.
    Execute the query
    Click back
    You can see the statistics.
    Thanks
    Chandran

  • Report execution time is in milliseconds

    My report execution time is in milliseconds.Where should i examine this time?

    If u have permisssions to see the log..(logging level >2) then you can see your execution time in the following path
    setting--->Administration------>Manage Sessions------>View Log
    In that you can find different sections which can give your the execution time
    -------------------- Physical query response time
    -------------------- Physical Query Summary Stats
    -------------------- Logical Query Summary Stats

  • DTP Execution Time is different when run by PC & Manually

    Dear Experts,
    Could you please help me in finding the answers for the below questions.
    1. Execution time for DTp is higher when ran manually  and using process chain. What can be the possible reasons & whic one is correct?
    2. Total Exceution time mentioned in the DTP details ta is less when added the total time for each data package. What are the reason for that difference. Which is correct?
    Thanks & regards,
    Ganesh Thota

    Hi,
    1)Execution time depends on various factors like the number of processes running on the system on a particular time(Ucan check it in SM37)
       in Process chain an instance of the particular process type is created( in your case process type is DTP even though we execute DTP in PC it originally executes the DTP in RSA1 .. i.e., an instance is created)
    2)the thing is when u execute a DTP data is transferred in the form of Packages the mismatch in the execution type is because u might have added the timings of each data package
    but when you check clearly :  2-3 data packages in DTP  start at the same time so you should not add the time taken of each individual data package to get the total time of the DTP
    Hope it answers you questions
    Regards,
    MADhu

  • Huge difference in Execution time in same Query with different Parameter

    Hi Experts,
    We are facing an unique problem once we are executing the query in HANA SQL prompt. This Query was generated from BObj and executing in HANA system. Once this query running with following condition, it is taking almost 7-00 minute to execute and returning around 924 rows.
    << WHERE
    Table__1."LOGSYS"  IN  ('RKGCLNT102')
    AND
    Table__1."CompanyCode"  IN  ('7240','7245')
    AND
    Table__1."Plant"  IN ……………… >
    However if we run the same query with some different plant, It is taking only 2 second. Please find the Query here.
    << WHERE
    Table__1."LOGSYS"  IN  ('RKGCLNT102')
    AND
    Table__1."CompanyCode"  IN  ('7245','7600')
    AND
    Table__1."Plant"  IN ……………… >
    This is really an unexpected behavior and we are not able to get the actual reason why it is behaving like this.
    Could anyone please help to analyze this issue to fine the root cause.
    Thanks in Advance.
    Regards
    Satrajit.

    Hi there
    Unfortunately you provided too few information to analyze the issue.
    Maybe the underlying tables have very skew data and the first select has to read a larger share of the base tables.
    Maybe the columns had been unloaded before and the first query had to load them into memory first.
    Is the runtime always bad with the one and always good with the other set of parameters?
    Have you checked the PlanViz for both versions? How do these differ?
    - Lars

  • Query Execution Time for a Query causing ORA-1555

    dear Gurus
    I have ORA-01555 error , earlier I used the Query Duration mentioned in Alert Log and increased the Undo Retention as I did not find th UnDOBLKS column of v$undostat high for the time of occurence of ORA-01555..
    But new ORA-01555 is coming whose query duration exceeds Undo Retention time..
    My question -
    1. Is it possible to accurately find the query duration time besides the Alert Log file ?

    abhishek, as you are using an undo tablespace and have already increased the time that undo data is retained via undo_retention then you might want to consider the following ideas which were useful with 1555 error under manual rbs segment management.
    1- Tune the query. The faster a query runs the less likely a 1555 will occur.
    2- Look at the processing. If a process was reading and updating the same table while committing frequenctly then the process under manual rbs management would basically create its own 1555 error rather than just being the victum of another process changing data and the rbs data being overlaid while the long running query was still running. With undo management the process could be generating more data than can be held for the undo_retention period but because it is committed Oracle has been told it doesn't really have to keep the data for use rolling back a current transaction so it gets discarded to make room for new changes.
    If you find item 2 is true then separating the select from the update will likely eliminate the 1555. You do this by building a driving table that has the keys of the rows to be updated or deleted. Then you use the driver to control accessing the target table.
    3- If the cause of the 1555 is or may be delayed block cleanout then select * from the target prior to running the long running query.
    Realistically you might need to increase the size of the undo tablespace to hold all the change data and the value of the undo_retention parameter to be longer than the job run time. Which brings up back to option 1. Tune every query in the process so that the job run time is reduced to optimal.
    HTH -- Mark D Powell --
    dear mark
    Thanks for the excellent advise..I found that the error is coming because of frequent commits..which is item 2 as u righly mentioned ..
    I think I need to keep a watch on the queries running , I was just trying to find the execution time for the queries..If there is any way to find the query duration without running a trace ..
    regards
    abhishek

  • How can I get the elapse time for execution of a Query for a session

    Hi ,
    How can I get the elapse time for execution of a Query for a session?
    Example - I have a report based on the procedure ,when the user execute that it takes say 3 min. to return rows.
    Is there any possible way to capture this session info. for this particular execution of query along with it's execution elapse time?
    Thanks in advance.

    Hi
    You can use the dbms_utility.get_time tool (gives binary_integer type value).
    1/ Initialize you time and date of beginning :
    v_beginTime := dbms_utility.get_time ;
    2/ Run you procedure...
    3/ Get end-time with :
    v_endTime := dbms_utility.get_time ;
    4/ Thus, calculate elapsed time by difference :
    v_elapsTime := v_endTime - v_beginTime ;
    This will give you time elapsed in of 100th of seconds...
    Then you can format you result to give correct print time.
    Hope it will help you.
    AL

  • Bug in sqlserver 2014 long processing time in query optimizer for complex query. With compatibility set to 2012, everything is quick.

    Believe the bug to be related to the new cardinality estimator. In my case joining 7 tables it took 4 seconds to see the query execution plan, with 8 tables it took 1 minute and with 9 tables 15
    minutes! the actual processing of the query plan was sub second. (each table has only two records...)
    It looks as if there is a workload in the cardinality estimator that escalates as the number of tables and join columns increases.
    We have a number of these queries in our application and the bug is a showstopper for our customers. They will have to set compatibility level to 110 (sqlserver 2012) to run the app. Then they should
    probably not upgrade from 2012...
    Is this a known bug? What is the bug number? How can I follow the bug to see when it is fixed?
      Here is my testcase: (first building tables and data, and then the query with some comments. A version spending 15 minutes in the optimizer, takes 0 seconds to complete with the hint "option (QUERYTRACEON 9481) ".  we can't use this
    hint in the application because no dba will allow an application like ours to run as sysadmin...
    SCRIPT:
    -- Example has one table containing 25 rows. another containing 2 rows. 
    -- The one with two rows is joined in several times. 
    -- In the original query each of these joins were to separate tables. 
    -- I use this simplification because it makes it easier to build the testcase.
    ------------  CREATE TEST CASE   ----------
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[oleclient](
    [acc_f_agio] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_f_dag] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_notes_ap] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_notes_ar] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_per_cost] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_per_inc] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_reverse] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_undec_ap] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_undec_ar] [varchar](25) NOT NULL DEFAULT (' '),
    [acc_vat_pay] [varchar](25) NOT NULL DEFAULT (' '),
    [attr_id_balance] [varchar](4) NOT NULL DEFAULT (' '),
    [bal_acc_v2] [varchar](25) NOT NULL DEFAULT (' '),
    [bal_acc_v3] [varchar](25) NOT NULL DEFAULT (' '),
    [balance_acc] [varchar](25) NOT NULL DEFAULT (' '),
    [bank_fee_acc] [varchar](25) NOT NULL DEFAULT (' '),
    [bflag] [int] NOT NULL DEFAULT ((0)),
    [client] [varchar](25) NOT NULL DEFAULT (' '),
    [client_name] [varchar](255) NOT NULL DEFAULT (' '),
    [comp_reg_no] [varchar](25) NOT NULL DEFAULT (' '),
    [compress_flag] [tinyint] NOT NULL DEFAULT ((0)),
    [country] [varchar](255) NOT NULL DEFAULT (' '),
    [country_code] [varchar](25) NOT NULL DEFAULT (' '),
    [cur_client] [varchar](25) NOT NULL DEFAULT (' '),
    [cur_item] [tinyint] NOT NULL DEFAULT ((0)),
    [cur_type] [varchar](25) NOT NULL DEFAULT (' '),
    [cur_type_tri] [varchar](25) NOT NULL DEFAULT (' '),
    [curr_period] [int] NOT NULL DEFAULT ((0)),
    [currency] [varchar](25) NOT NULL DEFAULT (' '),
    [currency_tri] [varchar](25) NOT NULL DEFAULT (' '),
    [currency_v2] [varchar](25) NOT NULL DEFAULT (' '),
    [currency_v3] [varchar](25) NOT NULL DEFAULT (' '),
    [diff_acc_v2] [varchar](25) NOT NULL DEFAULT (' '),
    [diff_acc_v3] [varchar](25) NOT NULL DEFAULT (' '),
    [diff_account] [varchar](25) NOT NULL DEFAULT (' '),
    [diff_chk_v2] [tinyint] NOT NULL DEFAULT ((0)),
    [diff_chk_v3] [tinyint] NOT NULL DEFAULT ((0)),
    [dim_v2_type] [varchar](25) NOT NULL DEFAULT (' '),
    [dim_v3_type] [varchar](25) NOT NULL DEFAULT (' '),
    [employer_id] [varchar](12) NOT NULL DEFAULT (' '),
    [header] [varchar](30) NOT NULL DEFAULT (' '),
    [header2] [varchar](30) NOT NULL DEFAULT (' '),
    [headquarter] [varchar](25) NOT NULL DEFAULT (' '),
    [language] [varchar](2) NOT NULL DEFAULT (' '),
    [last_update] [datetime] NOT NULL DEFAULT (CONVERT([datetime],'19000101 00:00:00:000',(9))),
    [leg_act_cli] [varchar](25) NOT NULL DEFAULT (' '),
    [max_inv_diff] [decimal](28, 3) NOT NULL DEFAULT ((0.0)),
    [max_inv_diff_v2] [decimal](28, 3) NOT NULL DEFAULT ((0.0)),
    [max_inv_diff_v3] [decimal](28, 3) NOT NULL DEFAULT ((0.0)),
    [max_pay_diff] [decimal](28, 3) NOT NULL DEFAULT ((0.0)),
    [max_pay_diff_v2] [decimal](28, 3) NOT NULL DEFAULT ((0.0)),
    [max_pay_diff_v3] [decimal](28, 3) NOT NULL DEFAULT ((0.0)),
    [municipal] [varchar](25) NOT NULL DEFAULT (' '),
    [overrun_pct] [decimal](28, 8) NOT NULL DEFAULT ((0.0)),
    [pay_client] [varchar](25) NOT NULL DEFAULT (' '),
    [pay_diff_acc_g] [varchar](25) NOT NULL DEFAULT (' '),
    [pay_diff_acc_l] [varchar](25) NOT NULL DEFAULT (' '),
    [pay_ref] [varchar](25) NOT NULL DEFAULT (' '),
    [period_no] [smallint] NOT NULL DEFAULT ((0)),
    [remind_ref] [varchar](20) NOT NULL DEFAULT (' '),
    [rev_vat_disc_ap] [tinyint] NOT NULL DEFAULT ((0)),
    [rev_vat_disc_ar] [tinyint] NOT NULL DEFAULT ((0)),
    [sys_setup_code] [varchar](2) NOT NULL DEFAULT (' '),
    [tax_office_no] [varchar](50) NOT NULL DEFAULT (' '),
    [tax_office_ref] [varchar](20) NOT NULL DEFAULT (' '),
    [tax_system] [varchar](25) NOT NULL DEFAULT (' '),
    [user_id] [varchar](25) NOT NULL DEFAULT (' '),
    [vat_reg_no] [varchar](25) NOT NULL DEFAULT (' '),
    [agrtid] [bigint] IDENTITY(1,1) NOT NULL,
    UNIQUE NONCLUSTERED 
    [agrtid] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
      ('8081','8181',' ',' ','2442','1481','9998',' ',' ','1320',' ','9998',' ',' ','8110','0','UK','Agresso Demo UK','987654321012','0','United Kingdom','GB','UK','1','1','EU','200409','GBP','EUR','EUR','USD','9998','9998','9998','1','0','EU','$',' ','Agresso
    demo','Corporate Office','NO','EN','2004-09-27 12:39:00.000','UK',0.020,0.000,0.000,0.100,0.000,0.000,'0301',0.00000000,'UK','9998','9998','Jim Smith','12','Mike Anderson','0','0','EN','Bristol Brunel','V123/123',' ','JOSUTTON','123456789101');
    insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
       ('8060','8160',' ',' ','2960','1480','1490',' ',' ',' ',' ',' ',' ',' ','7770','0','N1','N1 - Énklient','971332421','0','Norway','NO','N1','0','1',' ','200701','NOK',' ','EUR',' ',' ',' ','9999','0','0','E',' ','971332421','Agresso Demo Norge (NO)','Agresso
    Demo Norge (NO)','NO','NO','2007-01-26 08:31:00.000','N1',0.050,0.000,0.000,0.500,0.000,0.000,'0301',5.00000000,'N1','9999','9999',' ','12',' ','0','0','NO',' ',' ',' ','SYSNO','971332421');
    insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
     ('900000','900000',' ',' ',' ',' ','900100',' ',' ',' ',' ',' ',' ',' ','470000','0','BE','DEMO Belgie',' ','0','Belgium','BE','BE','0','1',' ','200208','EUR',' ','USD','GBP',' ',' ','900100','0','0','2','3',' ',' ','Agresso Business World','BE','EN','2005-11-18
    17:07:00.000','BE',0.050,0.000,0.000,0.050,0.000,0.000,'2018',0.00000000,'BE','900100','900100',' ','12',' ','0','0','BT',' ',' ',' ','SYSBE','BE461149381');
      insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('8030','8040',' ',' ','1250','2450','9998',' ',' ',' ',' ',' ',' ',' ','8060','0','A99','Seneca N.V. - Reporting / Intellagent',' ','0',' ','NL','A99','0','1',' ','201105','EUR',' ','USD',' ',' ',' ','9998','0','0','2',' ',' ','Seneca N.V. - Report / Intell','Seneca
    N.V. - Report / Intell','A01','EN','2011-05-19 12:19:59.000','A99',0.010,0.000,0.000,5.000,0.000,0.000,' ',0.00000000,'A99','9998','9998',' ','12',' ','0','0','EN',' ',' ',' ','SYSTEM',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('766000','666000','445860','445870','486000','487000',' ','445806','445807','445806',' ',' ','DEVISES',' ',' ','3','FR','Agresso Demo France',' ','0','France','FR','FR','1','1','1','200509','EUR','EUR',' ','FRF',' ','DEVISES','471000','0','1',' ','1',' ','Agresso
    demo France','Agresso demo France','FR','FR','2005-08-30 09:27:00.000','FR',0.100,0.000,0.500,10.000,0.000,0.000,'92',0.00000000,'FR',' ',' ',' ','12',' ','0','0','FR',' ',' ',' ','SYSFR','FR12345678');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ','9999',' ',' ',' ',' ',' ',' ',' ',' ','0','AU','Agresso Australia','123456789','0','Australia','AU','AU','0','1',' ','200708','AUD',' ',' ',' ',' ',' ','9999','0','0',' ',' ',' ','Agresso demo Australia','Corporate Office','AU','AU','2007-04-19
    12:40:00.000','AU',0.000,0.000,0.000,0.000,0.000,0.000,' ',0.00000000,'AU','9999','9999',' ','12',' ','0','0','AU',' ',' ',' ','SYSAU','123456789')
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('8060','8160',' ',' ','2960','1480','1490',' ',' ',' ',' ',' ',' ',' ','7770','0','NO','Agresso Demo Norge (NO)','971332425','0','Norway','NO','NO','0','1',' ','201401','NOK',' ','EUR',' ',' ',' ','9999','0','0','E',' ','971332425','Agresso Demo Norge (NO)','Agresso
    Demo Norge (NO)','NO','NO','2014-01-11 12:34:54.000','NO',0.050,0.000,0.000,0.500,0.000,0.000,'0301',5.00000000,'NO','9999','9999',' ','12',' ','0','0','NO',' ',' ',' ','SYSNO','971332425');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('9999','9999',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','9999','0','SF','Agresso Demo SF',' ','0','Finland','SF','SF','0',' ',' ','0','FIM',' ',' ',' ',' ',' ','9999','0','0',' ',' ',' ','Agresso Demo','Hovedkontoret','SF','SE','1996-01-18 03:25:00.000','SF',0.000,0.000,0.000,0.000,0.000,0.000,'
    ',0.00000000,'SF','9999','9999',' ','12',' ','0','0','SF',' ',' ',' ','SYSTEM',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','US','Agresso Demo Corp.',' ','0',' ','US','US','1',' ',' ','199702','USD',' ',' ',' ',' ',' ',' ','0','0',' ',' ',' ','Agresso Demo Corp.','Headquarter','US','US','1997-01-21 02:45:00.000','US',0.020,0.000,0.000,5.000,0.000,0.000,'
    ',0.00000000,'US',' ',' ','John Smith','12','Elsa Beskow','0','0','EN',' ',' ',' ','SYSNO',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('8081','8181',' ',' ','2442','1481','9998',' ',' ','1320',' ','9998',' ',' ','8110','0','EN','Agresso Demo','987654321012','0','United Kingdom','GB','EN','1','1','EU','201401','GBP','EUR','EUR','USD','9998','9998','9998','1','0','EU','$',' ','Agresso demo','Corporate
    Office','NO','EN','2014-01-06 10:20:58.000','EN',0.020,0.010,0.000,0.100,0.000,0.000,'0301',0.00000000,'EN','9998','9998','Jim Smith','12','Mike Anderson','0','0','EN',' ',' ',' ','SYSEN','123456789101');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','10','Test company 10 (for multiclient)',' ','0',' ','GB','EN','0','1',' ','200801','GBP',' ',' ',' ',' ',' ',' ','0','0',' ',' ',' ','Test company 10 (multiclient)','Test company 10 (multiclient)','EN','EN','2008-05-07
    10:57:51.000','EN',0.010,0.000,0.000,1.000,0.000,0.000,' ',0.00000000,'EN',' ',' ',' ','12',' ','0','0','EN',' ',' ',' ','SYSEN',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('4840','6880',' ',' ','1900','3900',' ','1410','3810','3810',' ','9998','9998',' ',' ','1','DE','D3 Demo Fibu/Projekt/Logistik','1277777001','0',' ','DE','DE','1','1','1','200204','EUR','EUR','USD','DEM','9998','9998','9998','1','1','2','1',' ','Agresso Demo
    Fibu/Pr/Log','Agresso Demo Fibu/Pr/Log','DE','DE','2002-04-03 17:28:00.000','DE',0.050,0.000,0.000,5.000,0.000,0.000,' ',0.00000000,'DE','4720','4720',' ','12',' ','0','0','DE','Finanzamt München II',' ',' ','SYSDE','DE888999777');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','PF','Performance test company',' ','0',' ','GB','PF','0','1',' ','200910','GBP',' ',' ',' ',' ',' ',' ','0','0',' ',' ',' ',' ',' ','PF','EN','2009-10-14 15:49:10.000','PF',0.000,0.000,0.000,0.000,0.000,0.000,'
    ',0.00000000,'PF',' ',' ',' ','12',' ','0','0','EN',' ',' ',' ','SYSEN',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','01','RD Reporting Team - Test Client 01',' ','0',' ','NO','01','0',' ',' ','201101',' ',' ',' ',' ',' ',' ',' ','0','0',' ',' ',' ',' ',' ','01','EN','2013-10-22 13:29:46.000','01',0.000,0.000,0.000,0.000,0.000,0.000,'
    ',0.00000000,'01',' ',' ',' ','12','Vidar Bjørnson','0','0','EN',' ',' ',' ','REPDEV',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','02','RD Reporting Team - Test Client 02',' ','0',' ','NO','02','0',' ',' ','201101',' ',' ',' ',' ',' ',' ',' ','0','0',' ',' ',' ',' ',' ','01','EN','2013-10-22 13:30:11.000','02',0.000,0.000,0.000,0.000,0.000,0.000,'
    ',0.00000000,'02',' ',' ',' ','12','Vidar Bjørnson','0','0','EN',' ',' ',' ','REPDEV',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','03','RD Reporting Team - Test Client 03',' ','0',' ','NO','03','0',' ',' ','201101',' ',' ',' ',' ',' ',' ',' ','0','0',' ',' ',' ',' ',' ','01','EN','2013-10-22 13:30:47.000','03',0.000,0.000,0.000,0.000,0.000,0.000,'
    ',0.00000000,'01',' ',' ',' ','12','Vidar Bjørnson','0','0','EN',' ',' ',' ','REPDEV',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','9998',' ',' ',' ','0','FP','FIN PROC Test Project','321456987','0',' ','NO','FP','0','1','1','201206','EUR','EUR','USD','USD','9998','9998',' ','1','1','2','2',' ','FIN PROC Test Project','FIN PROC Test Project','FP','EN','2012-09-24
    10:43:27.000','FP',0.000,0.000,0.000,0.000,0.000,0.000,' ',0.00000000,'FP',' ',' ',' ','12',' ','0','0','EN',' ',' ',' ','FRODE','321456987MVA');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    (' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','DM','Agresso Deployment Manager',' ','0',' ','NO','DM','0',' ',' ','201301',' ',' ',' ',' ',' ',' ',' ','0','0',' ',' ',' ',' ',' ','DM','EN','2013-11-06 13:55:17.000','DM',0.000,0.000,0.000,0.000,0.000,0.000,'
    ',0.00000000,'DM',' ',' ',' ','12',' ','0','0','EN',' ',' ',' ','SYSEN',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('3960','7960',' ',' ','1790','2990','2991',' ',' ',' ',' ',' ',' ',' ','6570','0','S1','Agresso Demo Client S1','556558-7893','0','Sweden','SE','S1','1','1',' ','200401','SEK',' ','NOK','EUR','8322','8321','3740','1','1','3','6','5565587893',' ','Utbildningsföretaget
    AB','SE','SE','2005-02-10 22:04:00.000','S1',0.500,0.000,0.000,0.500,0.000,0.000,' ',0.00000000,'S1','3740','3740','Anna Kronstam','12','Thomas Jelf','0','0','SE',' ',' ',' ','SYSEN','SE556558789301');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('3960','7960',' ',' ','1790','2990','2991',' ',' ',' ',' ',' ',' ',' ','6570','0','S2','Agresso Demo Client S2','556558-7893','0','Sweden','SE','S2','1','1',' ','200202','SEK',' ','NOK','EUR','8322','8321','3740','1','1','3','6','5565587893',' ','Utbildningsföretaget
    AB','SE','SE','2005-01-17 13:20:00.000','S2',0.500,0.000,0.000,0.500,0.000,0.000,' ',0.00000000,'S2','3740','3740','Anna Kronstam','12','Thomas Jelf','0','0','SE',' ',' ',' ','SYSSE','SE556558789301');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('910156','910166',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0','NL','DEMO Nederland','KVK9937465','0','Holland','NL','NL','0','1',' ','200708','EUR',' ',' ',' ',' ',' ','999999','0','0',' ',' ',' ','Global Trada N.V.','Global Trada N.V.','NL','NL','2007-08-15
    13:41:00.000','NL',50000.000,0.000,0.000,50000.000,0.000,0.000,'3994 DB',0.00000000,'NL','470720','470720',' ','12',' ','0','0','NL',' ',' ',' ','ROB','NL009404296B01');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('4664','4730',' ',' ','4755',' ',' ',' ',' ',' ',' ',' ',' ',' ','4755','0','DK','Agresso Demo Denmark',' ','0','Denmark','DK','DK','0','1',' ','0','DKK',' ',' ',' ',' ',' ',' ','0','0',' ',' ','0123456789','Agresso Denmark','Agresso Denmark','DK','DK','2005-10-14
    08:40:00.000','DK',0.100,0.000,0.000,0.100,0.000,0.000,' ',0.00000000,'DK',' ',' ',' ','12',' ','0','0','DK',' ',' ',' ','SYSDK',' ');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('76800','66800',' ',' ','48000','48500','99999','47201','47701',' ',' ',' ',' ',' ','66910','1','SP','Agresso Spain',' ','0','Spain','ES','SP','0','1','1','200804','EUR','EUR','GBP',' ',' ',' ','99999','0','0','2',' ',' ','Agresso DEMO S.A','Agresso DEMO S.A','SP','ES','2008-04-07
    14:01:38.000','SP',0.010,0.000,0.000,0.010,0.000,0.000,' ',0.50000000,'SP','99999','99999','Dpto.Aministración','12','Dpto.Riesgos','0','0','ES','00007307','18ru0456',' ','SYSES','B18389742');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('3960','7960',' ',' ','1790','2990','2991',' ',' ',' ',' ','8439',' ',' ','6570','0','SE','UTBILDNINGSFÖRETAGET AB','2021001235','0',' ','SE','SE','0','1',' ','200707','SEK',' ','EUR',' ','8439',' ','3740','1','0','2',' ',' ','Masterföretaget AB','Masterföretaget
    AB','SE','SE','2008-06-09 12:38:43.000','SE',0.500,0.000,0.000,0.500,0.000,0.000,'STLM',0.05000000,'SE','3740','3740',' ','12',' ','0','0','SE',' ','Stockholm',' ','SYSEN','SE202100123501');
     insert into oleclient (
     acc_f_agio, acc_f_dag, acc_notes_ap, acc_notes_ar, acc_per_cost, acc_per_inc, acc_reverse, acc_undec_ap, acc_undec_ar, acc_vat_pay, attr_id_balance, bal_acc_v2, bal_acc_v3, balance_acc,
     bank_fee_acc, bflag, client, client_name, comp_reg_no, compress_flag, country, country_code,  cur_client, cur_item, cur_type, cur_type_tri, curr_period, currency, currency_tri,
     currency_v2, currency_v3, diff_acc_v2, diff_acc_v3, diff_account, diff_chk_v2, diff_chk_v3, dim_v2_type, dim_v3_type, employer_id, header, header2, headquarter, language,
     last_update, leg_act_cli, max_inv_diff, max_inv_diff_v2, max_inv_diff_v3, max_pay_diff, max_pay_diff_v2, max_pay_diff_v3, municipal, overrun_pct, pay_client, pay_diff_acc_g,
     pay_diff_acc_l, pay_ref, period_no, remind_ref, rev_vat_disc_ap, rev_vat_disc_ar, sys_setup_code, tax_office_no, tax_office_ref, tax_system, user_id, vat_reg_no )
     values
    ('8081','8181',' ',' ','2442','1481','9998','1301','1307','1320',' ','9998',' ',' ','8110','1','IT','IT - Client',' ','0','Italy','IT','IT','1','EU','EU','200601','EUR','EUR','EUR','USD','9998','9998','9998','1','0','EU','$','CODE SIA','Agresso demo Italia','Corporate
    Office','IT','IT','2006-09-28 08:46:00.000','IT',0.020,0.000,0.000,0.100,0.000,0.000,'0301',0.00000000,'IT','9998','9998','Jim Smith','12','Mike Anderson','0','0','IT','Tax authority province','Auto-no011299',' ','SYSEN','11465420153');
    go
    CREATE UNIQUE NONCLUSTERED INDEX [aioleclient1] ON [dbo].[oleclient]
    [client] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
    GO
    CREATE TABLE [dbo].[Htable1](
    [amount] [decimal](28, 3) NOT NULL DEFAULT ((0)),
    [cur_amount] [decimal](28, 3) NOT NULL DEFAULT ((0)),
    [value_2] [decimal](28, 3) NOT NULL DEFAULT ((0)),
    [value_3] [decimal](28, 3) NOT NULL DEFAULT ((0)),
    [currency] [varchar](25) NOT NULL DEFAULT (' '),
    [client] [varchar](25) NOT NULL DEFAULT (' '),
    [asset_id] [varchar](25) NOT NULL DEFAULT (' '),
    [depr_book_id] [varchar](25) NOT NULL DEFAULT (' '),
    [input_id] [bigint] NOT NULL DEFAULT ((0)),
    [amount_type] [char](25) NOT NULL DEFAULT (' '),
    [reval_year] [int] NOT NULL DEFAULT ((0)),
    [trans_seq] [int] NOT NULL DEFAULT ((0)),
    [sequence_no] [int] NOT NULL DEFAULT ((0)),
    [at_trans_date] [datetime] NOT NULL DEFAULT (CONVERT([datetime],'19000101',(112))),
    [agrtid] [bigint] IDENTITY(1,1) NOT NULL,
    UNIQUE NONCLUSTERED 
    [agrtid] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    INSERT INTO Htable1 (at_trans_date,amount,amount_type,asset_id,client,cur_amount,currency,depr_book_id,input_id,reval_year,sequence_no,trans_seq,value_2,value_3) 
     VALUES ('20140603' ,0.00000000,'GLN','BM','EN',0.00000000,'GBP','BUSINESS',563,0,29,0,0.00000000,0.00000000 ) 
    GO
    INSERT INTO Htable1 (at_trans_date,amount,amount_type,asset_id,client,cur_amount,currency,depr_book_id,input_id,reval_year,sequence_no,trans_seq,value_2,value_3) 
     VALUES ('20140603' ,0.00000000,'GLN','BM','EN',0.00000000,'GBP','BUSINESS',563,0,30,0,0.00000000,0.00000000 ) 
    GO
    --=================================================================================
    -- The following query takes 15 minutes on my computer to give an execution plan. Fetching the data takes no additional time.
    -- removing one table (CACHED88) from the query brings the time down to 59 seconds.
    -- removing one more (CACHED87) brings it down to 4 seconds.
    -- adding the hint "option (QUERYTRACEON 9481)" to the first case, brings it down from 15 minutes to less than one second!
    SELECT 
           CACHED83.amount - ( CACHED76.amount + CACHED75.amount + CACHED85.amount + CACHED86.amount + CACHED87.amount + CACHED88.amount) AS amount, 
           CACHED83.amount - ( CACHED76.amount + CACHED75.amount + CACHED85.amount + CACHED86.amount + CACHED87.amount + CACHED88.amount) AS cur_amount, 
           c.currency    
    FROM 
           Htable1   tab1 , 
           Htable1   CACHED83 , 
           Htable1   CACHED76 ,
           Htable1   CACHED75 ,
           Htable1   CACHED85 ,
           Htable1   CACHED86 ,
           Htable1   CACHED87 ,
           Htable1   CACHED88 ,
           oleclient c  
    WHERE 
           tab1.client = c.client AND
           tab1.amount_type = 'GLN' AND 
           tab1.asset_id     = CACHED83.asset_id AND 
           tab1.depr_book_id = CACHED83.depr_book_id AND        
           tab1.client       = CACHED83.client AND 
           tab1.input_id     = CACHED83.input_id AND 
           tab1.reval_year   = CACHED83.reval_year AND     
           tab1.trans_seq    = CACHED83.trans_seq AND 
           tab1.sequence_no  = CACHED83.sequence_no AND 
           tab1.asset_id     = CACHED76.asset_id AND  
           tab1.depr_book_id = CACHED76.depr_book_id AND 
           tab1.client       = CACHED76.client AND 
           tab1.input_id     = CACHED76.input_id AND  
           tab1.reval_year   = CACHED76.reval_year AND 
           tab1.trans_seq    = CACHED76.trans_seq AND 
           tab1.sequence_no  = CACHED76.sequence_no AND 
           tab1.asset_id     = CACHED75.asset_id AND 
           tab1.depr_book_id = CACHED75.depr_book_id AND 
           tab1.client       = CACHED75.client AND      
           tab1.input_id     = CACHED75.input_id AND 
           tab1.reval_year   = CACHED75.reval_year AND 
           tab1.trans_seq    = CACHED75.trans_seq AND       
           tab1.sequence_no  = CACHED75.sequence_no AND 
           tab1.asset_id     = CACHED85.asset_id AND 
           tab1.depr_book_id = CACHED85.depr_book_id AND        
           tab1.client       = CACHED85.client AND 
           tab1.input_id     = CACHED85.input_id AND 
           tab1.reval_year   = CACHED85.reval_year AND     
           tab1.trans_seq    = CACHED85.trans_seq AND 
           tab1.sequence_no  = CACHED85.sequence_no AND 
           tab1.asset_id     = CACHED86.asset_id AND 
           tab1.depr_book_id = CACHED86.depr_book_id AND 
           tab1.client       = CACHED86.client AND 
           tab1.input_id     = CACHED86.input_id AND  
           tab1.reval_year   = CACHED86.reval_year AND 
           tab1.trans_seq    = CACHED86.trans_seq AND 
           tab1.sequence_no  = CACHED86.sequence_no AND  
           tab1.asset_id     = CACHED87.asset_id AND 
           tab1.depr_book_id = CACHED87.depr_book_id AND 
           tab1.client       = CACHED87.client AND      
           tab1.input_id     = CACHED87.input_id AND 
           tab1.reval_year   = CACHED87.reval_year AND 
           tab1.trans_seq    = CACHED87.trans_seq AND       
           tab1.sequence_no  = CACHED87.sequence_no  AND  
           tab1.asset_id     = CACHED88.asset_id AND 
           tab1.depr_book_id = CACHED88.depr_book_id AND 
           tab1.client       = CACHED88.client AND      
           tab1.input_id     = CACHED88.input_id AND 
           tab1.reval_year   = CACHED88.reval_year AND 
           tab1.trans_seq    = CACHED88.trans_seq AND       
           tab1.sequence_no  = CACHED88.sequence_no  
    --  option (QUERYTRACEON 9481)         

    Reading "What's new in Sql Server 2014" (http://msdn.microsoft.com/en-us/library/bb510411.aspx#CE). I see that  it says:
    New Design for Cardinality Estimation
    The cardinality estimation logic, called the cardinality estimator, is re-designed in SQL Server 2014 to improve the quality of query plans, and therefore to improve query performance. The new cardinality estimator incorporates assumptions and algorithms
    that work well on modern OLTP and data warehousing workloads. It is based on in-depth cardinality estimation research on modern workloads, and our learnings over the past 15 years of improving the SQL Server cardinality estimator. Feedback from customers shows
    that while most queries will benefit from the change or remain unchanged, a small number might show regressions compared to the previous cardinality estimator. For performance tuning and testing recommendations, seeCardinality
    Estimation (SQL Server).
    I states that a "small number of queries might show regressions". To mee the regression is a showstopper and seems to have to do with complexity. I found one query reported by Juha Salo (bug 893758) that possibly could have to do with the same thing.
    It is a query with many joins. Simplifying the query by removing one of the joins, makes it work fine. The query documented in his report does not need any setup as it is a query on system tables as sys.indexes and sys.index_columns.
    I quote:
    There is a huge difference in performance for the following query between compatibility level 120 and the lower levels:
    dbcc dropcleanbuffers
    SELECT i.NAME
    FROM sys.indexes i
    INNER JOIN sys.index_columns k ON i.object_id = k.object_id
    AND i.index_id = k.index_id
    INNER JOIN sys.objects o ON i.object_id = o.object_id
    AND k.object_id = o.object_id
    INNER JOIN sys.index_columns k1 ON i.object_id = k1.object_id
    AND i.index_id = k1.index_id
    AND k1.key_ordinal = 1
    INNER JOIN sys.index_columns k2 ON i.object_id = k2.object_id
    AND i.index_id = k2.index_id
    AND k2.key_ordinal = 2
    INNER JOIN sys.index_columns k3 ON i.object_id = k3.object_id
    AND i.index_id = k3.index_id
    AND k3.key_ordinal = 3
    INNER JOIN sys.index_columns k4 ON i.object_id = k4.object_id
    AND i.index_id = k4.index_id
    AND k4.key_ordinal = 4
    INNER JOIN sys.index_columns k5 ON i.object_id = k5.object_id
    AND i.index_id = k5.index_id
    AND k5.key_ordinal = 5
    INNER JOIN sys.index_columns k6 ON i.object_id = k6.object_id
    AND i.index_id = k6.index_id
    AND k6.key_ordinal = 6
    INNER JOIN sys.index_columns k7 ON i.object_id = k7.object_id
    AND i.index_id = k7.index_id
    AND k7.key_ordinal = 7
    INNER JOIN sys.columns c1 ON o.object_id = c1.object_id
    AND k1.column_id = c1.column_id
    INNER JOIN sys.columns c2 ON o.object_id = c2.object_id
    AND k2.column_id = c2.column_id
    INNER JOIN sys.columns c3 ON o.object_id = c3.object_id
    AND k3.column_id = c3.column_id
    INNER JOIN sys.columns c4 ON o.object_id = c4.object_id
    AND k4.column_id = c4.column_id
    INNER JOIN sys.columns c5 ON o.object_id = c5.object_id
    AND k5.column_id = c5.column_id
    INNER JOIN sys.columns c6 ON o.object_id = c6.object_id
    AND k6.column_id = c6.column_id
    INNER JOIN sys.columns c7 ON o.object_id = c7.object_id
    AND k7.column_id = c7.column_id
    Can be run in any database. In our case we have a legacy database with almost 10 000 (ten thousand) tables. In that kind of database the query just freezes fully utilizing a single cpu core.
    If compatibility level is switched to 110 then query performs as it should.

  • Reduce execution time with selects

    Hi,
    I have to reduce the execution time in a report, most of the consumed time is in the select query.
    I have a table, gt_result:
    DATA: BEGIN OF gwa_result,
          tknum            LIKE vttk-tknum,
          stabf            LIKE vttk-stabf,
          shtyp            LIKE vttk-shtyp,
          route            LIKE vttk-route,
          vsart            LIKE vttk-vsart,
          signi            LIKE vttk-signi,
          dtabf            LIKE vttk-dtabf,
          vbeln            LIKE likp-vbeln,
          /bshm/le_nr_cust LIKE likp-/bshm/le_nr_cust,
          vkorg            LIKE likp-vkorg,
          werks            LIKE likp-werks,
          regio            LIKE kna1-regio,
          land1            LIKE kna1-land1,
          xegld            LIKE t005-xegld,
          intca            LIKE t005-intca,
          bezei            LIKE tvrot-bezei,
          bezei1           LIKE t173t-bezei,
          fecha(10) type c.
    DATA: END OF gwa_result.
    DATA: gt_result LIKE STANDARD TABLE OF gwa_result.
    And the select query is this:
      SELECT ktknum kstabf kshtyp kroute kvsart ksigni
    k~dtabf
             lvbeln l/bshm/le_nr_cust lvkorg lwerks   nregio nland1 oxegld ointca
                 tbezei   ttbezei
      FROM vttk AS k
      INNER JOIN vttp  AS p ON ktknum = ptknum
      INNER JOIN likp  AS l ON pvbeln = lvbeln
      INNER JOIN kna1  AS n ON lkunnr = nkunnr
      INNER JOIN t005  AS o ON nland1 = oland1
      INNER JOIN tvrot AS t ON troute = kroute AND t~spras = sy-langu
      INNER JOIN t173t AS tt ON ttvsart = kvsart AND tt~spras = sy-langu
      INTO TABLE gt_result
      WHERE ktknum IN s_tknum AND ktplst IN s_tplst AND k~route IN s_route AND
         k~erdat BETWEEN s_erdat-low AND s_erdat-high AND
         l~/bshm/le_nr_cust <> ' '    "IS NOT NULL
         AND k~stabf = 'X'
         AND ktknum NOT IN ( SELECT tktknum  FROM vttk AS tk
                             INNER JOIN vttp AS tp ON tktknum = tptknum
                             INNER JOIN likp AS tl ON tpvbeln = tlvbeln
                             WHERE l~/bshm/le_nr_cust IS NULL )
         AND k~tknum NOT IN ( SELECT tknum FROM /bshs/ssm_eship )
         AND ( o~xegld = ' '
               OR ( o~xegld = 'X' AND
                    ( ( n~land1 = 'ES'
                        AND ( nregio = '51' OR nregio = '52'
                              OR nregio =  '35' OR nregio =  '38' ) )
                               OR n~land1 = 'ESC' ) )
                      OR ointca = 'AD' OR ointca = 'GI' ).
    Does somebody know how to reduce the execution time ?.
    Thanks.

    Hi,
    Try to remove the join. Use seperate selects as shown in example below and for the sake of selection, keep some key fields in your internal table.
    Then once your final table is created, you can copy the table into GT_FINAL which will contain only fields you need.
    EX
    data : begin of it_likp occurs 0,
             vbeln like likp-vbeln,
             /bshm/le_nr_cust like likp-/bshm/le_nr_cust,
             vkorg like likp-vkorg,
             werks like likp-werks,
             kunnr likr likp-kunnr,
           end of it_likp.
    data : begin of it_kna1 occurs 0,
           kunnr like...
           regio....
           land1...
          end  of it_kna1 occurs 0,
    Select tknum stabf shtyp route vsart signi dtabf
    from VTTP
    into table gt_result
    WHERE tknum IN s_tknum AND
          tplst IN s_tplst AND
          route IN s_route AND
          erdat BETWEEN s_erdat-low AND s_erdat-high.
    select vbeln /bshm/le_nr_cust
           vkorg werks kunnr
           from likp
           into table it_likp
           for all entries in gt_result
           where vbeln = gt_result-vbeln.
    select kunnr
           regio
           land1
           from kna1
           into it_kna1
           for all entries in it_likp.
    similarly for other tables.
    Then loop at gt result and read corresponding table and populate entire record :
    loop at gt_result.
    read table it_likp where vbeln = gt_result-vbeln.
    if sy-subrc eq 0.
      move corresponding fields of it_likp into gt_result.
      gt_result-kunnr = it_likp-kunnr.
      modify gt_result.
    endif.
    read table it_kna1 where kunnr = gt_result-vbeln.
    if sy-subrc eq 0.
      gt_result-regio = it-kna1-regio.
      gt_result-land1 = it-kna1-land1.
      modify gt_result.
    endif.
    endloop.

Maybe you are looking for

  • How do I remove a song from my iTunes account?

    How do I remove a song from my iTunes acct?

  • How To Make an Array from Multiple Choices of a Drop-Down Menu?

    I have a drop-down menu (or a scrollable list). Visitors can make multiple selection from the list. How do I put those selected items into an array?

  • Face Metadata accessible and/or can it be batch deleted?

    Is there there a way access and/or batch delete "Face" data? Many of my old (pre-digital) photos are scanned from the originals in photo albums. I also have taken a digital photograph of each album page to keep in Aperture for reference. I don't want

  • Message in notification but not main body

    Hi, I would deeply appreciate a solution for my problem. I mainly use Skype on my iPad and smartphone. When I receive a notification on my iPad, it's on my main screen when I switch on my iPad before I unlock it. After I have done the same and open m

  • VAT credit reverse

    Dear Expert, We have a situation with VAT. There is one material code which when purchased as consumables VAT credit can be availed. But when used for repair and maintenance we cannot avail the VAT Credit. We have created Non deductible condition typ