Check Date range in between date range query

  • Hello friends,

    I need query which will check user supplied date range is in between the existing table startdate and enddate.

    if any of the date of user supplied date range is in between the tables start date and end date,it should retrun that record from table.

    for example user supply date range is from 1 may 2012 to 5 may 2012.

    then query must check that

    1 may 2005

    2 may 2005

    3 may 2005

    4 may 2005

    5 may 2005

    (all dates) is in between startdate and enddate of existing table.

    please reply...

  • two user parameteres in @StartDate and @EndDate

    two parameters to store min and max date in the table @MinDate and @MaxDate

    select the min and max date from the table

    SELECT @MinDate = MIN(DATE), @MaxDate = MAX(DATE) FROM table

    IF @StartDate >= @MinDate AND @EndDate <= @MaxDate

    BEGIN

    SELECT

    .....

    FROM

    .....

    JOIN

    ....

    WHERE

    Date >= @StartDate AND Date <=@EndDate

    END

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

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