472,353 Members | 1,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Date parameters in queries

Hello

I'm using Access 2003, and I have a query (written in SQL) which has
two parameters and asks the user for two dates. This has been working
fine. Today I modified the query, removing the paramerters and hard-
coding some dates in, in dd/mm/yy format. To my surprise I got a
different number of records returned. I then, as an experiment, change
the date format to dd/mm/yyyy. This again returned a different number
of records, different to both previous instances. When I use the
parameters I get the same result, irrespective of the date format
used. Has anybody come across anything liek this before - I've
searched here and can't see and previous postings, but apologies if
this has been covered before. The query is only using one table, so
it's nothing particularly complicated. The full query (with
parameters) is pasted below.

PARAMETERS [Start Date] DateTime, [End Date] DateTime;
SELECT q01_Clients.*
FROM q01_Clients
WHERE (
(
q01_Clients.clt_A11c_AuthFormRecDate<=[Start Date]
AND
clt_A21a_RecordType=10
AND
(
clt_A21_RecordStatus=10 OR (clt_A23_DateClosed>=[Start Date])
)
AND
(
(q01_Clients.clt_A24_Department=10 AND clt_A98_Transferred = FALSE)
OR
(q01_Clients.clt_A24_Department=10 AND clt_A99_DateTransferred
>=[Start Date])
OR
(q01_Clients.clt_A24_Department=20 AND
(clt_A45_ResettlementOpenDate>=[Start Date] OR
clt_A45_ResettlementOpenDate is NULL))
))
OR
(
q01_Clients.clt_A11c_AuthFormRecDate BETWEEN [Start Date] AND [End
Date] AND q01_Clients.clt_A21a_RecordType=10
));

Many thanks in anticipation!

Stephen

Oct 12 '07 #1
2 2273
When you hard code it in the SQL are you wrapping it in #ddmmyyyy#?

Also, I believe access ALWAYS stores dates in American format, mmddyyyy
regardless of your localization settings.....ahh I found it...heh its even
got a reference to the access legend who I learned it from...

Function SQLDate(varDate As Variant) As String
'Got this from Allen Browne master of Access
'http://users.bigpond.net.au/abrowne1/ser-36.html
'Access forcess american date formate for all SQL!
'#mm/dd/yyyy hh:mm:ss#
If IsDate(varDate) Then
SQLDate = "#" & Format$(varDate, "mm\/dd\/yyyy") & "#"
End If
End Function

Hope that helps....

"Stevienashaa" <st**********@yahoo.co.ukwrote in message
news:11**********************@k35g2000prh.googlegr oups.com...
Hello

I'm using Access 2003, and I have a query (written in SQL) which has
two parameters and asks the user for two dates. This has been working
fine. Today I modified the query, removing the paramerters and hard-
coding some dates in, in dd/mm/yy format. To my surprise I got a
different number of records returned. I then, as an experiment, change
the date format to dd/mm/yyyy. This again returned a different number
of records, different to both previous instances. When I use the
parameters I get the same result, irrespective of the date format
used. Has anybody come across anything liek this before - I've
searched here and can't see and previous postings, but apologies if
this has been covered before. The query is only using one table, so
it's nothing particularly complicated. The full query (with
parameters) is pasted below.

PARAMETERS [Start Date] DateTime, [End Date] DateTime;
SELECT q01_Clients.*
FROM q01_Clients
WHERE (
(
q01_Clients.clt_A11c_AuthFormRecDate<=[Start Date]
AND
clt_A21a_RecordType=10
AND
(
clt_A21_RecordStatus=10 OR (clt_A23_DateClosed>=[Start Date])
)
AND
(
(q01_Clients.clt_A24_Department=10 AND clt_A98_Transferred = FALSE)
OR
(q01_Clients.clt_A24_Department=10 AND clt_A99_DateTransferred
>>=[Start Date])
OR
(q01_Clients.clt_A24_Department=20 AND
(clt_A45_ResettlementOpenDate>=[Start Date] OR
clt_A45_ResettlementOpenDate is NULL))
))
OR
(
q01_Clients.clt_A11c_AuthFormRecDate BETWEEN [Start Date] AND [End
Date] AND q01_Clients.clt_A21a_RecordType=10
));

Many thanks in anticipation!

Stephen

Oct 14 '07 #2
Thanks John (and Allen!). I've now recoded the dates the other way
around (they were already in #'s) and it works a treat. It's obvious
when you know - I'd thought I'd changed all date settings to UK
format, but I didn't realise that it did this - so thanks very much
for taking the time to sort this for me.

Stephen

Oct 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jmev7 | last post by:
I had a query with a criteria in a date field reading "> And <", and when run, it correctly prompted first for the param, and then for the param....
2
by: Adam | last post by:
Hi All, This may be a really obvious thing that I'm missing ... but if anyone can help, I'd appreciate it. I have MS Access 2000: I'm using...
7
by: Nicolae Fieraru | last post by:
Hi All, I have a table tblProducts where I have four fields:\ Index, ProductName, EnterDate (as Date/Time - Medium Date), PurchaseDate...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a...
6
by: Tony Miller | last post by:
All I have an aggregate query using the function Month & Year on a datereceived field ie: TheYear: Year() TheMonth: Month() These are the group...
9
by: mharrison | last post by:
Hello, I am developing a small java web-based car-pool booking system app which interacts with an access database. I am trying to write 2...
6
by: Mark | last post by:
Hi, i have an application which works with date. The regional settings of the computer (XP prof. dutch version) are set to French (Belgium)....
2
by: Jim Devenish | last post by:
I wish to create a crosstab query as the record source for a report. It needs to count data between selected dates which are entered by the user in...
3
by: RoadRunner | last post by:
Hi, I am having a problem. I have a very simple employee database. The client needs to see everything on a form before any updates or deletions...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.