473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

SQL date query. Please help me!

Si
Hi there.

I have a page on a website I am building where is want to look for all
records added in the last 60 days.

The date is added in short UK format, that is 25/12/2003 in an access
database. (set as a date field)

I am using <% session.lcid=2057 %> in my header to force UK date format.

My problem is, everything seems to be correct, but the query just returns
all records in the table.

The SQL query is

if request("lookup") = "latest" then
recent = FormatDateTime(Now()-60,vbShortDate)
end if
if request.querystring("lookup") = "latest" then
myquery="SELECT * FROM Property WHERE datein > " & recent & " ORDER BY
datein DESC"
else
myquery="SELECT * FROM Property WHERE department LIKE '%" &
request.querystring("lookup") & "%' AND pricefaieuro > " & MinPrice & " AND
pricefaieuro < " & MaxPrice & " ORDER BY reference DESC"
end if

The SQL output via response.write seems to be correct (see following)

SELECT * FROM Property WHERE datein > 07/10/2003 ORDER BY datein DESC

(I have also tried WHERE NOT datein < " & recent &" ........)

Does anyone know what the proplem may be. I have been looking at this for
hours now and last night and am no closer to fixing it.

Thanks in advance

Simon


Jul 19 '05 #1
4 4010
CJM
Have you run this SQL in Access itself? Did you get the same results?
Jul 19 '05 #2
"Si" wrote:
: if request.querystring("lookup") = "latest" then
: myquery="SELECT * FROM Property WHERE datein > " & recent & " ORDER BY
: datein DESC"

if request.querystring("lookup") = "latest" then
myquery="SELECT * FROM Property WHERE datein > '" & recent & "' ORDER BY
datein DESC"

Instead of returning this:

SELECT * FROM Property WHERE datein > 07/10/2003 ORDER BY datein DESC

....it should return this:

SELECT * FROM Property WHERE datein > '07/10/2003' ORDER BY datein DESC

You need the quotes around the date.

HTH...

--
Roland

This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.
-Technet Knowledge Base-
http://support.microsoft.com/default...&ln=EN-US&FR=0
-Technet Script Center-
http://www.microsoft.com/technet/tre...er/default.asp
-MSDN Library-
http://msdn.microsoft.com/library/default.asp
Jul 19 '05 #3
Si wrote:
Hi there.

I have a page on a website I am building where is want to look for all
records added in the last 60 days.

The date is added in short UK format, that is 25/12/2003 in an access
database. (set as a date field)

I am using <% session.lcid=2057 %> in my header to force UK date
format.

Start here:
http://www.aspfaq.com/show.asp?id=2040

Where the article says to use "YYYYMMDD" format, it's talking about SQL
Server. This format will not be recognized by Jet. For Access, it is best to
use "YYYY-MM-DD". And don't forget to delimit the date literal with hash
marks (#).

HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #4
If it was me I'd create a query in Access that returns the data from the
last 60 days, and call that query rather than dynamically building a SQL
Statement.

"Si" <simon@MY_PANTSnetforma.com> wrote in message
news:O8****************@news-binary.blueyonder.co.uk...
Hi there.

I have a page on a website I am building where is want to look for all
records added in the last 60 days.

The date is added in short UK format, that is 25/12/2003 in an access
database. (set as a date field)

I am using <% session.lcid=2057 %> in my header to force UK date format.

My problem is, everything seems to be correct, but the query just returns
all records in the table.

The SQL query is

if request("lookup") = "latest" then
recent = FormatDateTime(Now()-60,vbShortDate)
end if
if request.querystring("lookup") = "latest" then
myquery="SELECT * FROM Property WHERE datein > " & recent & " ORDER BY
datein DESC"
else
myquery="SELECT * FROM Property WHERE department LIKE '%" &
request.querystring("lookup") & "%' AND pricefaieuro > " & MinPrice & " AND pricefaieuro < " & MaxPrice & " ORDER BY reference DESC"
end if

The SQL output via response.write seems to be correct (see following)

SELECT * FROM Property WHERE datein > 07/10/2003 ORDER BY datein DESC

(I have also tried WHERE NOT datein < " & recent &" ........)

Does anyone know what the proplem may be. I have been looking at this for
hours now and last night and am no closer to fixing it.

Thanks in advance

Simon


Jul 19 '05 #5

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

Similar topics

1
by: Yong Wang | last post by:
> Hi: > We have a database system. In the database, we have an > attribute called date0, which contains date data (format: > i. e. 2004-08-12). I wrote a script to fetch the data > in a...
1
by: Raghu | last post by:
Hello... I am running into a problem while running a query..can some1 help.. this is the query : ************** SELECT * from Table S where S.dtDate1 BETWEEN...
17
by: Lapchien | last post by:
My table has a record called date/time - filled (not surprisingly) with a date and time. I can format the date in one query field, also the time, using format in an expression. My user wants me...
2
by: Giulio | last post by:
I make an import of a huge file txt table with headers at each page and date format as "20.12.2004" in order to use the data I first qo a query that exclude all line representing the headers...
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 (Date/Time - Medium Date) The EnterDate is automatically...
67
by: PC Datasheet | last post by:
Transaction data is given with date ranges: Beginning End 4/1/06 4/4/06 4/7/06 4/11/06 4/14/06 4/17/06 4/18/06 4/21/06 426/06 ...
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 queries: The first which will specify whether a given car...
4
by: Simon Gare | last post by:
Hi all, I am trying to retrieve a count of booking entries made 30 days ago, below is the end of the query I am having problems with. dbo.booking_form.TimeOfBooking = DATEADD(day, -30,...
2
by: sixdeuce62 | last post by:
Hello, I am trying to create a query that will prompt me to enter the parameter value if beginning date and ending date. I have created everything I need in the query, but I have to manually go...
8
by: Dr Al | last post by:
I have a table with four date fields, some of which may not be filled in based on our data entry needs. I have a criteria set as <date()-180 which is supposed to pull dates older than 180 days ago....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.