Date range criteria

  • I have a table with 2 date fields- One startDate and other EndDate.

    I need a query to fetch records from this table based on a date range criteria. 

    Example:

    Id         StartDate        EndDate

    1          01 aug 2005     15 aug 2005

    2          10 sep 2005     12 dec 2005

    3          18 sep 2005      20 nov 2005

    If i pass 2 paramterers @startdate = 15 sep 2005 and @enddate = 01 nov 2005, the result i need is only 2nd record.

    Thanks is advance......

  • Something like this?

    Select Columns from dbo.TableName where StartDate @EndDate

  • Thanks, But the actual result not like that.

    I have 2 date ranges, the table values may fall in between this dates or may overlap the table values.

    Pls help.....

     

     

  • Try the link below to use DATEDIFF function with timespan which gives you time interval without time interval function.  Hope this helps.

    http://www.stanford.edu/~bsuter/sql-datecomputations.html

    Kind regards,

    Gift Peddie 

    Kind regards,
    Gift Peddie

  • Or maybe the BETWEEN function would be of use here

    June Shutt

  • It would help us immensely if you could describe in words, what is the desired result. From your post and example it is impossible to know precisely, several different conditions could satisfy it.

    For example, for a similar table of projects, you may wish to select projects that were running at least 1 day in the start-end period (StartDate < @enddate AND EndDate > @startdate), projects that were not running at all during the period (StartDate > @enddate OR EndDate < @startdate), running+finished projects (StartDate < @startdate), running+future projects (EndDate > @enddate), projects that were running the entire given period (StartDate < @startdate AND EndDate > @enddate) .... etc. Of course always with a possibility to include the borders using <=, >=.

    HTH, Vladan

  • select XXX from YYY where SpecifiedDate between @startdate and @enddate.

    I also have a script that runs the same task over and over with a different input parameter.

    Set the counter to 1, run the select statement above (where counter = 1), add 1 to counter run again etc.. until there are no more counters left in your table

    June Shutt

  • select * from table1 where <FirstDate Passed> between startdate and enddate and <Second Date Passed> between startdate and enddate

    this will give u the second record as expected

Viewing 8 posts - 1 through 7 (of 7 total)

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