PC Review


Reply
Thread Tools Rate Thread

Date query issue

 
 
BobC
Guest
Posts: n/a
 
      4th Mar 2009
I have a query that I need to pull the needs for a client for a specific date:

strSQL = "Select * From Needs " & _
"WHERE (((Needs.client_id)= " & dblClient_ID & ") And
((Needs.due_date)= #" & dtCalc_Date & "#)) ;"

The query is pulling all records for the client and seemingly ignoring the
date parameter. The date is in mm/dd/yyyy format.

This is what is visible in the object viewer for strSQL:
Select * From Needs WHERE (((Needs.client_id)= 2) And ((Needs.due_date)=
#2/1/2009#));


--
BobC

 
Reply With Quote
 
 
 
 
dymondjack
Guest
Posts: n/a
 
      4th Mar 2009
The string seems to be ok at first glance (you are using the # for comparing
a date), but I did notice the existance of the semicolon in your VBA version,
which I believe should be omitted.


So instead of
> strSQL = "Select * From Needs " & _
> "WHERE (((Needs.client_id)= " & dblClient_ID & ") And
> ((Needs.due_date)= #" & dtCalc_Date & "#)) ;"


try
strSQL = "Select * From Needs " & _
"WHERE (((Needs.client_id)= " & dblClient_ID & ") And
((Needs.due_date)= #" & dtCalc_Date & "#))"

I'm not sure if that's the issue or not, but I thought I'd point it out.

--
Jack Leach
www.tristatemachine.com

- "First, get your information. Then, you can distort it at your leisure."
- Mark Twain


"BobC" wrote:

> I have a query that I need to pull the needs for a client for a specific date:
>
> strSQL = "Select * From Needs " & _
> "WHERE (((Needs.client_id)= " & dblClient_ID & ") And
> ((Needs.due_date)= #" & dtCalc_Date & "#)) ;"
>
> The query is pulling all records for the client and seemingly ignoring the
> date parameter. The date is in mm/dd/yyyy format.
>
> This is what is visible in the object viewer for strSQL:
> Select * From Needs WHERE (((Needs.client_id)= 2) And ((Needs.due_date)=
> #2/1/2009#));
>
>
> --
> BobC
>

 
Reply With Quote
 
fredg
Guest
Posts: n/a
 
      4th Mar 2009
On Wed, 4 Mar 2009 13:55:01 -0800, BobC wrote:

> I have a query that I need to pull the needs for a client for a specific date:
>
> strSQL = "Select * From Needs " & _
> "WHERE (((Needs.client_id)= " & dblClient_ID & ") And
> ((Needs.due_date)= #" & dtCalc_Date & "#)) ;"
>
> The query is pulling all records for the client and seemingly ignoring the
> date parameter. The date is in mm/dd/yyyy format.
>
> This is what is visible in the object viewer for strSQL:
> Select * From Needs WHERE (((Needs.client_id)= 2) And ((Needs.due_date)=
> #2/1/2009#));


1) Try getting rid of the parenthesis. You don't need them here.
Sometimes they obscure the syntax.
strSQL = "Select * From Needs " & _
"WHERE client_id = " & dblClient_ID & " And
due_date = #" & dtCalc_Date & "#;"

2) Most likely however, is that your dtCalc_Date field includes a time
value.
2/1/2009 midnight is not the same as 2/1/2009 3:00 PM

See if you get records using:

..... " And due_date >= #" & dtCalc_Date & "# And due_Date < # " &
dtCalc_Date & " # + 1;"


--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
 
Reply With Quote
 
BobC
Guest
Posts: n/a
 
      4th Mar 2009
Thanks. The issue isn't that I'm not getting any records, it appears as
though the date portion of the where clause is getting ignored because I am
getting all records for the client.

--
BobC



"fredg" wrote:

> On Wed, 4 Mar 2009 13:55:01 -0800, BobC wrote:
>
> > I have a query that I need to pull the needs for a client for a specific date:
> >
> > strSQL = "Select * From Needs " & _
> > "WHERE (((Needs.client_id)= " & dblClient_ID & ") And
> > ((Needs.due_date)= #" & dtCalc_Date & "#)) ;"
> >
> > The query is pulling all records for the client and seemingly ignoring the
> > date parameter. The date is in mm/dd/yyyy format.
> >
> > This is what is visible in the object viewer for strSQL:
> > Select * From Needs WHERE (((Needs.client_id)= 2) And ((Needs.due_date)=
> > #2/1/2009#));

>
> 1) Try getting rid of the parenthesis. You don't need them here.
> Sometimes they obscure the syntax.
> strSQL = "Select * From Needs " & _
> "WHERE client_id = " & dblClient_ID & " And
> due_date = #" & dtCalc_Date & "#;"
>
> 2) Most likely however, is that your dtCalc_Date field includes a time
> value.
> 2/1/2009 midnight is not the same as 2/1/2009 3:00 PM
>
> See if you get records using:
>
> ..... " And due_date >= #" & dtCalc_Date & "# And due_Date < # " &
> dtCalc_Date & " # + 1;"
>
>
> --
> Fred
> Please respond only to this newsgroup.
> I do not reply to personal e-mail
>

 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      5th Mar 2009
strSQL = "Select * From Needs " & _
" WHERE Needs.client_id= " & dblClient_ID & _
" And Needs.due_date= #" & dtCalc_Date & "#"
'Add the following to check the actual statement being generated.
Debug.Print StrSQL
'Add the following to check the values of dblClient_ID/dtCalc_Date
Debug.Print dblClient_ID, dtCalc_Date

Something is going on, since that should be returing one client on one date.
'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================


BobC wrote:
> Thanks. The issue isn't that I'm not getting any records, it appears as
> though the date portion of the where clause is getting ignored because I am
> getting all records for the client.
>

 
Reply With Quote
 
BobC
Guest
Posts: n/a
 
      5th Mar 2009
Thanks, I will give that a try and let you know.


--
BobC



"John Spencer" wrote:

> strSQL = "Select * From Needs " & _
> " WHERE Needs.client_id= " & dblClient_ID & _
> " And Needs.due_date= #" & dtCalc_Date & "#"
> 'Add the following to check the actual statement being generated.
> Debug.Print StrSQL
> 'Add the following to check the values of dblClient_ID/dtCalc_Date
> Debug.Print dblClient_ID, dtCalc_Date
>
> Something is going on, since that should be returing one client on one date.
> '====================================================
> John Spencer
> Access MVP 2002-2005, 2007-2009
> The Hilltop Institute
> University of Maryland Baltimore County
> '====================================================
>
>
> BobC wrote:
> > Thanks. The issue isn't that I'm not getting any records, it appears as
> > though the date portion of the where clause is getting ignored because I am
> > getting all records for the client.
> >

>

 
Reply With Quote
 
BobC
Guest
Posts: n/a
 
      5th Mar 2009
The variables are displaying the correct values.

After running several more tests I found that the recordset.RecordCount is
correctly returning 0 for days where there are no records for the
client/date. However, if there is 1 or more records for the client/date the
recordset.RecordCount is returning the total count of all records for the
client in the needs table. The interesting thing is there really are only
the records for that client/date so when I do a recordset.MoveNext on a
client/date combination that I know only has 1 record for that date I get an
EOF condition. While this doesn’t present a logic problem because I’m
really only interested to know if anything for that client/date exists, it
does cause a significant performance issue. The query is inside a loop for
each day of the month and for large clients with “needs” on more than 1 or 2
days the performance is terrible.

If this is typical behavior for queries I may have to rework my logic and
put the query outside the loop and do the checks for each date while looping
through the recordset.


I am curious as to why the recordcount is returning a number different from
what the query is actually returning. (Access 2003)

--
BobC



"John Spencer" wrote:

> strSQL = "Select * From Needs " & _
> " WHERE Needs.client_id= " & dblClient_ID & _
> " And Needs.due_date= #" & dtCalc_Date & "#"
> 'Add the following to check the actual statement being generated.
> Debug.Print StrSQL
> 'Add the following to check the values of dblClient_ID/dtCalc_Date
> Debug.Print dblClient_ID, dtCalc_Date
>
> Something is going on, since that should be returing one client on one date.
> '====================================================
> John Spencer
> Access MVP 2002-2005, 2007-2009
> The Hilltop Institute
> University of Maryland Baltimore County
> '====================================================
>
>
> BobC wrote:
> > Thanks. The issue isn't that I'm not getting any records, it appears as
> > though the date portion of the where clause is getting ignored because I am
> > getting all records for the client.
> >

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate 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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
ACC2000 'query date' issue BrentDA Microsoft Access Queries 2 2nd Nov 2008 05:58 AM
Query Date issue ryan.fitzpatrick3@safeway.com Microsoft Access Form Coding 2 21st Feb 2008 09:49 PM
Re: Query Date issue Ron2006 Microsoft Access Form Coding 0 21st Feb 2008 07:52 PM
Year to Date Query Issue Steve Microsoft Access Queries 2 15th Feb 2007 02:59 PM
Re: Date Query Issue Gerald Stanley Microsoft Access Queries 2 26th Apr 2004 06:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:25 PM.