Need help writing a stored procedure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JJ297

    Need help writing a stored procedure

    How would I write a stored procedure to get * where duedate is less
    than and not equal to today's date. Is this right?

    select * from library
    where duedate < != getdate()

    Thanks
  • Plamen Ratchev

    #2
    Re: Need help writing a stored procedure

    You would write it like this:

    select * from library
    where duedate < getdate()

    However, since GETDATE() returns the current date and time, there are
    chances you will get duedate values for today, those between midnight and
    the current time. The correct way is to reset the current time portion to
    midnight. You will end up with something like this:

    SELECT <columns>
    FROM Library
    WHERE duedate < DATEADD(day, DATEDIFF(day, '20010101', CURRENT_TIMESTA MP),
    '20010101')

    In the above formula the time portion is trimmed by simple arithmetic:
    calculating the difference in days between a preset date (Jan-1-2001) and
    today, and then adding back the number of days to the same date. Since the
    DATEDIFF returns the number of days only, the time portion is discarded.

    And CURRENT_TIMESTA MP is just the ANSI SQL equivalent to GETDATE().

    HTH,

    Plamen Ratchev


    Comment

    • Jack Vamvas

      #3
      Re: Need help writing a stored procedure

      select * from library
      where duedate < getdate()



      --

      Jack Vamvas
      _______________ _______________ _____
      Search IT jobs from multiple sources- http://www.ITjobfeed.com




      "JJ297" <nc297@yahoo.co mwrote in message
      news:114cb8f8-6ac6-4b6b-a913-a676f6cb2634@s8 g2000prg.google groups.com...
      How would I write a stored procedure to get * where duedate is less
      than and not equal to today's date. Is this right?
      >
      select * from library
      where duedate < != getdate()
      >
      Thanks

      Comment

      Working...