• Lynn Pettis (1/15/2013)


    dwain.c (1/15/2013)


    2. When you check for a date range, BETWEEN is not recommended. You should use >= @StartDate and <= @EndDate.

    I'd like to expand on this one a bit. Actually, it should be:

    ... DateColumn >= @ StartDate and DateColumn < @EndDate

    For example, all records rows where the data is in the month of March 2012:

    declare @StartDate datetime = '20120301', -- Using datetime as the data is date/time oriented

    @EndDate datetime = '20120401'; -- or dateadd(mm,1,@StartDate)

    ... DateColumn >= @ StartDate and DateColumn < @EndDate

    Lynn - I agree with you. My brain was thinking in terms of a DATE datatype.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St