Conditional stuff...

  • Here's what I'd like to be able to do...

    *I have a July to June time frame

    *I have a Date field in the data

    *I have scheduled run dates for data retrieval

    I need to set up some sort of conditional check that takes the run date (GETDATE) and says, for example, if the run date falls in a particular July to June time frame, give me the records to date for that time frame.

    Ex. 1: Run date is 8/8/2005, so give me records where the Date field is from 7/1/2005 thru 8/8/2005

    Ex. 2: Run date is now 1/15/2006, so give me records where the Date field is from 7/1/2005 thru 1/15/2006

    Ex. 3: Run date is now 8/8/2006, so give me records where the Date field is from 7/1/2006 thru 8/8/2006

    *I am having a brain hiccup and can't seem to get the WHERE clause set up properly

    RJ

  • Calculate your "from date" this way:

    DECLARE @StartDay smalldatetime, @Today smalldatetime

    SET @StartDay = '1900-07-01'

    SET @Today = getdate()

    ... between dateadd(yy, datediff(yy, @StartDay, @Today), @StartDay) and @Today

    _____________
    Code for TallyGenerator

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

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