• Just want to point out that you are using the BETWEEN operator with a date field... if your date field can have time values in it, then you probably are not getting what you want.

    Each of the dates in the between clause will default to a time of "00:00:00.000". If you're looking for all dates on 8/14, then you need to either:

    1. Record_date between '8/12/2009' and '8/14/2009 23:59:59.997'

    OR

    2. Record_date >= '8/12/2009' and Record_date < '8/15/2009'

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2