Connecting Tech Pros Worldwide Help | Site Map
Reply
 
LinkBack Thread Tools Search this Thread
  #1  
Old September 4th, 2008, 11:35 AM
JustRun's Avatar
Member
 
Join Date: Mar 2008
Age: 25
Posts: 52
Default 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
Reply
  #2  
Old September 5th, 2008, 06:10 PM
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Age: 32
Posts: 2,407
Default

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

Jared
Reply
  #3  
Old September 8th, 2008, 12:28 PM
JustRun's Avatar
Member
 
Join Date: Mar 2008
Age: 25
Posts: 52
Default

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
Reply
  #4  
Old September 8th, 2008, 01:44 PM
DrBunchman's Avatar
Moderator
 
Join Date: Jan 2008
Location: Winchester, UK
Posts: 926
Default

Hi JustRun,

Try using
Expand|Select|Wrap|Line Numbers
  1.   AND (TaskTable.TaskDate >= @StartDate AND TaskTable.TaskDate < @EndDate)
Hope this helps,

Dr B
Reply
  #5  
Old September 9th, 2008, 11:29 AM
JustRun's Avatar
Member
 
Join Date: Mar 2008
Age: 25
Posts: 52
Default

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)
Reply
  #6  
Old September 9th, 2008, 12:01 PM
DrBunchman's Avatar
Moderator
 
Join Date: Jan 2008
Location: Winchester, UK
Posts: 926
Default

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
Reply
  #7  
Old September 9th, 2008, 01:08 PM
JustRun's Avatar
Member
 
Join Date: Mar 2008
Age: 25
Posts: 52
Default

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"
Reply
  #8  
Old September 9th, 2008, 01:27 PM
DrBunchman's Avatar
Moderator
 
Join Date: Jan 2008
Location: Winchester, UK
Posts: 926
Default

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
Reply
  #9  
Old September 10th, 2008, 08:29 AM
omerbutt's Avatar
Familiar Sight
 
Join Date: Nov 2006
Posts: 227
Default

Quote:
Originally Posted by DrBunchman
Hi JustRun,

Try using
Expand|Select|Wrap|Line Numbers
  1.   AND (TaskTable.TaskDate >= @StartDate AND TaskTable.TaskDate < @EndDate)
Hope this helps,

Dr B
Try using
Expand|Select|Wrap|Line Numbers
  1.   AND (Cdate(TaskTable.TaskDate)>= Cdate('"&StartDate&"') AND Cdate(TaskTable.TaskDate) < Cdate('"&EndDate&"'))
Hope this helps,
regards,
omer
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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.
Post your question now . . .
It's fast and it's free

Popular Articles