• Also, computing date ranges becomes easier if you use a closed end comparision on the lower end and an open end comparision on the upper end.

    For example, you want all records entered for the previous month, in this case July.

    declare @StartDate datetime,

    @EndDate datetime;

    select @StartDate = dateadd(mm, datediff(mm, 0, getdate()) - 1, 0), @EndDate = dateadd(mm, datediff(mm, 0 ,getdate()), 0);

    select @StartDate, @EndDate; -- display the start and end dates

    select

    mt.* -- would actually list the columns to be returned

    from

    dbo.MyTable mt

    where

    mt.MyDateColumn >= @StartDate and

    mt.MyDateColumn < @EndDate;