• Eirikur Eiriksson - Tuesday, May 8, 2018 7:21 AM

    Imke Cronje - Tuesday, May 8, 2018 6:55 AM

    Eirikur Eiriksson - Tuesday, May 8, 2018 6:45 AM

    Imke Cronje - Tuesday, May 8, 2018 6:24 AM

    Hi Guys,

    I have to optimize a query that takes hours to run. I cancelled the query because it takes a long time to run. The query makes us of temp tables and makes a left join to another temp table. Both table contains 19 millions records.

    The query is as follows:

    IF object_id ('tempdb..#table2') IS NOT NULL DROP TABLE #table2 
    select
    a.*, b.column1,b.column2,b.column3,b.column4
    into #table2 
    from #table1 a left join #table3 b on a.column1= b.column1 and a.column2= b.column2

    Any ideas how I can optimize this query? Any help will be much appreciated.

    Regards

    Please post the DDL (create table) scripts for all the tables, some data samples as insert statement and the execution plan!
    😎

    Hi,

    All tables are temp tables. They are created with the select Into statement.

    Post the actual plan, not an image please!
    😎

    Agreed, when it comes to execution plans, a picture is just a single word that says nothing.