Calculations in a query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jmmmmm
    New Member
    • Jan 2008
    • 1

    Calculations in a query

    I would like to do a date calculation between 2 fields in the query and return a result based on the calculation:

    ex:

    table x
    field date
    field duration


    SELECT * FROM x WHERE [date + duration] >= (somedate)

    Is this possible?
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    yes that is possible, you need to join both the tables for same.

    Comment

    • deepuv04
      Recognized Expert New Member
      • Nov 2007
      • 227

      #3
      Originally posted by jmmmmm
      I would like to do a date calculation between 2 fields in the query and return a result based on the calculation:

      ex:

      table x
      field date
      field duration


      SELECT * FROM x WHERE [date + duration] >= (somedate)

      Is this possible?
      hi
      your query is possible if the duration is number of days only.

      if you want to calculate for different kinds of duration like days, weeks, months and years then

      -- duration is number of days
      SELECT * FROM x WHERE DATEADD(day, duration, date ) >= (somedate)
      -- duration is number of weeks
      SELECT * FROM x WHERE DATEADD(day, duration * 7, date) >= (somedate)
      -- duration is number of months
      SELECT * FROM x WHERE DATEADD(Month, duration , date) >= (somedate)
      -- duration is number of years
      SELECT * FROM x WHERE DATEADD(year, duration , date) >= (somedate)

      Comment

      Working...