• For starters, both queries miss nearly a full second of the day identified in the WHERE clause. Use the following, instead.

    (TBL_1.DateTime >= '11-01-2014 09:00:00' AND TBL_1.DateTime < '12-01-2014 09:00:00)

    The other thing is that while just looking at code can sometimes reveal which will be faster, such looks are frequently wrong. The best way to find out is to do a test. Provided that the code has no scalar or multi-statement table valued functions in it, a quick check by adding the following code can be of real help especially when analyzed in conjunction with the actual execution plan.

    SET STATISTICS TIME, IO ON;

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)