Get all Records BETWEEN two dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JustRun
    New Member
    • Mar 2008
    • 127

    Get all Records BETWEEN two dates

    Hi,

    My problem is: I want to display employees tasks which recorded during two given dates

    I do this: select all dates based on employee ID, and place bind those dates to TWO dropdownlist "StartDate, EndDate".

    When the employee select a start date and end date I want to display him the tasks which are between those dates,

    Actually it works But, it will never work if the employee have just two records cause the condition here is Between and there will be nothing between two.

    The second thing when i tried to add (OR EndDate = @EndDate) the SQL querey manager gave an error msg.
    Here is my SQL code hope u help

    SELECT TaskTable.TaskD ate, TaskTable.TaskD escription, TaskTable.TimeS tart,
    TaskTable.TimeE nd, CustomerTable.C ustomerName, CustomerTable.P hone, CustomerTable.A ddress
    FROM TaskTable INNER JOIN CustomerTable ON TaskTable.Custo merID = CustomerTable.D ocumentID
    WHERE (TaskTable.Empl oyeeID = @EmployeeID)
    AND (TaskTable.Task Date BETWEEN @EndDate AND @StartDate) ORDER BY TaskTable.TaskD ate DESC
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    dates are supposed to be enclosed in "#" signs or some such depending on your db type. What db are you using?

    Jared

    Comment

    • JustRun
      New Member
      • Mar 2008
      • 127

      #3
      Originally posted by jhardman
      dates are supposed to be enclosed in "#" signs or some such depending on your db type. What db are you using?

      Jared
      Sorry for the late reply,

      My database is SQLSERVER 2000

      Thanks

      Comment

      • DrBunchman
        Recognized Expert Contributor
        • Jan 2008
        • 979

        #4
        Hi JustRun,

        Try using
        Code:
          AND (TaskTable.TaskDate >= @StartDate AND TaskTable.TaskDate < @EndDate)
        Hope this helps,

        Dr B

        Comment

        • JustRun
          New Member
          • Mar 2008
          • 127

          #5
          Actually it get the same result as (Between) , for example, if i put the start parameter value = 9/9/2008 it brings records starting from the date AFTER this record Even when I modified the sql statement to (TaskDate >= @StartDate)

          Comment

          • DrBunchman
            Recognized Expert Contributor
            • Jan 2008
            • 979

            #6
            That's not right as you can probably imagine - if @StartDate is 9/9/2008 then any records with a TaskDate of 9/9/2008 or later should be returned.

            What data type are your dates in the database?

            Are you formatting the @StartDate parameter before passing it in or are you passing it in as the string "9/9/2008"?

            Dr B

            Comment

            • JustRun
              New Member
              • Mar 2008
              • 127

              #7
              My Database SQLSERVER 2000,
              the data type of the (TaskDate, TimeStart, TimeEnd) are all (dateTime) and I pass the parameter as datetime exactly like its data type,

              I know that the Where Clause that you wrote it is the right one cause in Logic , but The SQLSERVER view its result as same as that one of between, "it leave the first record"

              Comment

              • DrBunchman
                Recognized Expert Contributor
                • Jan 2008
                • 979

                #8
                If you remove all other conditions from your where clause so you are just filtering by the date condition does it still have the same effect?

                Are you running this query in SQL Server Management Studio?

                Dr B

                Comment

                • omerbutt
                  Contributor
                  • Nov 2006
                  • 638

                  #9
                  Originally posted by DrBunchman
                  Hi JustRun,

                  Try using
                  Code:
                    AND (TaskTable.TaskDate >= @StartDate AND TaskTable.TaskDate < @EndDate)
                  Hope this helps,

                  Dr B
                  Try using
                  Code:
                    AND (Cdate(TaskTable.TaskDate)>= Cdate('"&StartDate&"') AND Cdate(TaskTable.TaskDate) < Cdate('"&EndDate&"'))
                  Hope this helps,
                  regards,
                  omer

                  Comment

                  Working...