 | 
September 4th, 2008, 11:35 AM
|  | Member | | Join Date: Mar 2008 Age: 25
Posts: 52
| | 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.TaskDate, TaskTable.TaskDescription, TaskTable.TimeStart,
TaskTable.TimeEnd, CustomerTable.CustomerName, CustomerTable.Phone, CustomerTable.Address
FROM TaskTable INNER JOIN CustomerTable ON TaskTable.CustomerID = CustomerTable.DocumentID
WHERE (TaskTable.EmployeeID = @EmployeeID)
AND (TaskTable.TaskDate BETWEEN @EndDate AND @StartDate) ORDER BY TaskTable.TaskDate DESC
| 
September 5th, 2008, 06:10 PM
|  | Moderator | | Join Date: Jan 2007 Location: logan, utah Age: 32
Posts: 2,407
| |
dates are supposed to be enclosed in "#" signs or some such depending on your db type. What db are you using?
Jared
| 
September 8th, 2008, 12:28 PM
|  | Member | | Join Date: Mar 2008 Age: 25
Posts: 52
| | Quote: |
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
| 
September 8th, 2008, 01:44 PM
|  | Moderator | | Join Date: Jan 2008 Location: Winchester, UK
Posts: 926
| |
Hi JustRun,
Try using - AND (TaskTable.TaskDate >= @StartDate AND TaskTable.TaskDate < @EndDate)
Hope this helps,
Dr B
| 
September 9th, 2008, 11:29 AM
|  | Member | | Join Date: Mar 2008 Age: 25
Posts: 52
| |
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)
| 
September 9th, 2008, 12:01 PM
|  | Moderator | | Join Date: Jan 2008 Location: Winchester, UK
Posts: 926
| |
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
| 
September 9th, 2008, 01:08 PM
|  | Member | | Join Date: Mar 2008 Age: 25
Posts: 52
| |
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"
| 
September 9th, 2008, 01:27 PM
|  | Moderator | | Join Date: Jan 2008 Location: Winchester, UK
Posts: 926
| |
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
| 
September 10th, 2008, 08:29 AM
|  | Familiar Sight | | Join Date: Nov 2006
Posts: 227
| | Quote: |
Originally Posted by DrBunchman Hi JustRun,
Try using - AND (TaskTable.TaskDate >= @StartDate AND TaskTable.TaskDate < @EndDate)
Hope this helps,
Dr B | Try using - AND (Cdate(TaskTable.TaskDate)>= Cdate('"&StartDate&"') AND Cdate(TaskTable.TaskDate) < Cdate('"&EndDate&"'))
Hope this helps,
regards,
omer
|  | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 204,687 network members.
|