query by todays date +7

  • I have to set up a SQL Script that extracts the appointment data I need for 7 days from now.

    I am running the following SQL for the select having to manually enter the date 7 days from now

    (vw_Ixp_appointments.appdate_dte >= '2010-10-18 00:00')

    AND (vw_Ixp_appointments.appdate_dte <= '2010-10-18 23:59')

    I know that I can also run the following but it doesn’t return any results….

    (vw_Ixp_appointments.appdate_dte = (GETDATE () +7))

    Question is how can the above be modified (if possible) to accommodate the date format our data uses or am I doing something wrong?

  • Check out DateAdd

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

    /T

  • Hi ,

    please see this article , essential reading imo

    http://www.karaszi.com/SQLServer/info_datetime.asp



    Clear Sky SQL
    My Blog[/url]

  • Sorted now, Cheers

  • If appdate_dte is a datetime column, the date format is irrelevant. You'll be comparing a date with a date, no formatting applies.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 5 posts - 1 through 4 (of 4 total)

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