Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2005
    Posts
    19

    Unanswered: BETWEEN clause & <= operators

    Hi ,

    In a stored procedure when retrieving records based on a DATETIME values in WHERE clause - can we use BETWEEN clause or Col <= AND Col >= ?

    Please suggest which is the optimised way.

    Thanks in Advance,

    Hari Haran Arulmozhi

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    They are both the same. The optimser comverts BETWEEN to >= and <= anyway. Depends on what you prefer to type\ read. I like BETWEEN as I don't have to check if there is a >= to correspond with any <= I find.

    HTH
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    optimized approach for datetime ranges involving two dates is actually to use something like this --

    Code:
     where datetimecol >= '2006-08-09'
       and datetimecol  < '2006-08-11'
    this returns all datetimes for the 9th and the 10th

    using BETWEEN you have two choices -- code the upper value as '2006-08-10 23:59:59.999' (clumsy) or code the upper end as '2006-08-11' (and risk getting a row from the 11th at midnight)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •