How can I get the dates I need?

  • date1 >= 01/01/2013 --@STARTDATE

    date1 <= 02/28/2013 --@ENDDATE

    columns:

    quote# date1 date2

    1 01/01/2013 12/21/2012 <----This date is within -30 days of date1

    2 02/17/2013 01/25/2013 <----This date is within -30 days of date1

    3 02/08/2013 11/03/2012 <----This date is not within -30 days of date1

    I do not want to return this row.

    I only want to return a row if the date2 column is within -30 days of date1

  • I think you might be looking for the DATEDIFF function

    http://msdn.microsoft.com/en-us/library/ms189794.aspx

  • rick.servant (5/10/2013)


    date1 >= 01/01/2013 --@STARTDATE

    date1 <= 02/28/2013 --@ENDDATE

    columns:

    quote# date1 date2

    1 01/01/2013 12/21/2012 <----This date is within -30 days of date1

    2 02/17/2013 01/25/2013 <----This date is within -30 days of date1

    3 02/08/2013 11/03/2012 <----This date is not within -30 days of date1

    I do not want to return this row.

    I only want to return a row if the date2 column is within -30 days of date1

    Give this a try:

    select * from dbo.QuoteData where date2 >= dateadd(dd, -30, date1);

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

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