Date Range cunundrum

  • I have this date parameter that I would like to edit.

    BETWEEN DATEADD(MONTH, - 6, @StartDate) AND dbo.DateOnly(@StartDate))

    Can you help me change this so that it goes from the first day of the 6th month to the start date?

    (eg, when I select 12/17/2010 as the start date, the range will be: 6/1/2010 to 12/17/2010)

    Thank you in advance for your help! It is much appreciated!

  • Something like this perhaps?

    BETWEEN DATEADD( mm, DATEDIFF( mm, 0, @StartDate) - 6, 0) AND DATEADD( dd, DATEDIFF( dd, 0, @StartDate), 0)

    Note I removed your dbo.DateOnly function and swapped it out for the currently best known method for speed.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • thanks! that worked!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply