Between & Dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DanBWeb
    New Member
    • Sep 2007
    • 5

    #1

    Between & Dates

    I am trying to query SQL, based on a date

    For each term I have a record in the "TermDate" table:

    TemName StartDate EndDate
    Term 1 9/1/2007 11/21/2007
    Term 2 11/22/2007 1/29/2008
    Term 3 ... ...

    Seems easy enough, but I can't get it to pull the appropriate record. if xDate = 9/20/2007, the query should return me Term 1, for example.

    Both date fields are smalldate types

    I tried using a "Between" statement, but that didnt go to well - any ideas?
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Originally posted by DanBWeb
    I am trying to query SQL, based on a date

    For each term I have a record in the "TermDate" table:

    TemName StartDate EndDate
    Term 1 9/1/2007 11/21/2007
    Term 2 11/22/2007 1/29/2008
    Term 3 ... ...

    Seems easy enough, but I can't get it to pull the appropriate record. if xDate = 9/20/2007, the query should return me Term 1, for example.

    Both date fields are smalldate types

    I tried using a "Between" statement, but that didnt go to well - any ideas?
    Can you post your query? Is there an error? a

    Code:
    WHERE @xDate between StartDate and EndDate
    should be fine. I'm assuming xDate is a variable.

    -- CK

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      Are you getting any error from the query or simply not getting the desired output ?

      Comment

      • amitpatel66
        Recognized Expert Top Contributor
        • Mar 2007
        • 2358

        #4
        Try converting xDate to date variable of format MM/DD/YYYY when used with BETWEEN clause

        Comment

        Working...