• I would be interested in seeing the plan for this ..

    Select TradeID,DataSource.DataSourceID

    FROM

    dbo.Trade

    INNER JOIN dbo.DataSource ON dbo.DataSource.DataSourceID=dbo.Trade.DataSourceID

    WHERE

    (

    ( dbo.Trade.TradeDate >= DATEADD(DD, -1 * DAY(GETDATE()), DATEADD(MM, -1 * MONTH(GETDATE()) + 1, GETDATE())))

    )

    As the orignal plan timed-out this *could* come back with a decent plan.

    Sorry for probably stupid question, but how to let SQL engine know that there are 465,000 rows? I rebuilt all the indexes(thought it might help), but had no luck with it.

    Thats the problem, both of the tables here have a decent estimate of rows but its the join output that doesent.

    This could be a bug/hole in the optimizer the above will help prove/disprove that.

    Im anycase it still sounds to me a better option to use the above query , store the results in a temp table and drive the remainder from that.

    HTH

    The plan view i use is sql sentry plan explorerer , its a free download too 🙂

    Dave



    Clear Sky SQL
    My Blog[/url]