Home Forums SQL Server 2008 T-SQL (SS2K8) Select statement of view stays 5 hours to return results...... RE: Select statement of view stays 5 hours to return results......

  • There are several approaches you can use:

    Most important:

    instead of applying a function to your columns rewrite it as SARGable arguments:

    datediff(d, i.LstMdfation, getdate()) < 30

    -- would be

    i.LstMdfation>dateadd(dd, -30, getdate())

    Another option that usually helps is preaggregation.

    Find the table that would be reduced the most by your where conditions and populate that table as an indexed temp table and use this table in your query.

    Furthermore, you're calling Artcl at least four times. Maybe the query itself can be rewritten to be much more efficient.

    And finally, there might be a missing index issue, too. Check the execution plan for best index usage.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]