473,467 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

still stuck on query strings

I should just get a hat with a big D on it and then everyone would recognise
me..

anyway...

I have a DB full of people and their details..

I'm trying to perform a query based on age.

so I have a form with two values..upperlimit and lowerlimit ( eg aged
between 25 and 30, but worked out in years so that upper limit gives a birth
year of 1974 and lowerlimit gives a birth year of 1979)

my query string looks like

strSQL = "SELECT * FROM users where ( (right(dob,4)) =>" & lowerlimit & "
AND " & " (right(dob,4)) =<" & upperlimit & ")order by key"

so..dob is the DB field for date of birth, I'm just taking the year from
this hence the right(dob,4) and looking for entries where the year of dob is
more than AND less than the search criteria

the error message I get is

Syntax error (missing operator) in query expression

I must be missing something obvious...

on a lighter note...I'm certainly getting there as I've managed to get most
of the queries working..just not this one....lol

thanks again

Jul 19 '05 #1
4 1294
On Mon, 5 Jan 2004 17:01:54 -0000, "Alistair"
<news@*remove*alistairb.co.uk> wrote:

"Aaron Bertrand - MVP" <aa***@TRASHaspfaq.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> strSQL = "SELECT * FROM users where ( (right(dob,4)) =>" & lowerlimit
&
"
> AND " & " (right(dob,4)) =<" & upperlimit & ")order by key"


Why do you think right(dob,4) is valid for a date? You realize that dates
aren't stored how they are presented, right? And that you shouldn't be
treating dates as strings? Also, what operations are >= and =< ?

Try

strSQL = "SELECT * FROM users WHERE dob >= #" & lowerlimit & "-01-01# AND
dob < #" & upperlimit+1 & "-01-01# ORDER BY key"

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


thanks for that Aaron, I know what you mean about strings and
numbers...guess I got confused as right(dob,4)) gave me 1965 or whatever
and although your string works perfectly, I don't understand how it works.
whats the # and 01-01 for?


# is the Microsoft Access delimiter for dates. The -01-01 is month
01, day 01 for whatever year. As in YYYY-MM-DD notation, which is how
date formats are handled. (In the US at least).
is there a page I can look this up?...I hate using something I don't
understand ("stick to gardening" I hear you cry)


Gardening? My gardening skill amounts to "Plant it. If it dies,
plant something else."

FWIW, I was converting dates to strings for a long time to handle
them, though doing so outside the query, using DatePart and so on.
SQL Books Online has a bunch of date stuff, as does MSDN, but in
Access you have a really pretty decent help system built in. Go to
Help, and search for "Dates in Queries" or the like and you'll get a
decent reference.

Plus, you can build the query in Access, then look at the queyr in SQL
view and that's pretty much the code you need in your strSQL, with the
exception of single vs. double quotes.

Jeff
Jul 19 '05 #2
> 01, day 01 for whatever year. As in YYYY-MM-DD notation, which is how
date formats are handled. (In the US at least).


Actually, it's one of the ISO date formatting standards. Pity that the only
reliable standard in Access (YYYY-MM-DD) is not the same as the only
reliable format in SQL Server (YYYYMMDD).

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
Jul 19 '05 #3
On Mon, 5 Jan 2004 14:25:03 -0500, "Aaron Bertrand - MVP"
<aa***@TRASHaspfaq.com> wrote:
01, day 01 for whatever year. As in YYYY-MM-DD notation, which is how
date formats are handled. (In the US at least).


Actually, it's one of the ISO date formatting standards. Pity that the only
reliable standard in Access (YYYY-MM-DD) is not the same as the only
reliable format in SQL Server (YYYYMMDD).


Especially since I switch between SQL and Access, and get bit every
single time. :)

Jeff
Jul 19 '05 #4
One solution: stop using Crapcess. :-)

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"Jeff Cochran" <jc*************@naplesgov.com> wrote in message
news:3f****************@msnews.microsoft.com...
On Mon, 5 Jan 2004 14:25:03 -0500, "Aaron Bertrand - MVP"
<aa***@TRASHaspfaq.com> wrote:
01, day 01 for whatever year. As in YYYY-MM-DD notation, which is how
date formats are handled. (In the US at least).


Actually, it's one of the ISO date formatting standards. Pity that the onlyreliable standard in Access (YYYY-MM-DD) is not the same as the only
reliable format in SQL Server (YYYYMMDD).


Especially since I switch between SQL and Access, and get bit every
single time. :)

Jeff

Jul 19 '05 #5

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

Similar topics

1
by: theboss3 | last post by:
I am having trouble with accessing files with query strings. For example the code "require 'template.php?102932'" gives the following error: Warning: main(/www/blog/template.php?102932):...
23
by: Peter Row | last post by:
Hi, I am currently working on a VB.NET project that has been going for quite a while. In the past it has been developed with a lot of compatibility VB6 functions and constants, e.g Left(),...
6
by: Darrel | last post by:
*sigh*...I have gotten no where with my .net 2.0 project. ;o) I'm still stuck on db connection strings. I have a connection string in my web config: <appSettings> <add key="DBConn" value=""...
1
by: colleen1980 | last post by:
When I run my query it stuck is it possible that i can debug it SELECT TOP 1 tblCredits.OPR, Min(tbl_CRCDollars.SumOfAMOUNT) AS MinOfSumOfAMOUNT, Avg(tblCredits.Credit) AS AvgOfCredit,...
3
by: Nathan Guill | last post by:
I have an interface that works with an Access back-end. I would like to store and/or load user defined query strings per each user (i.e. no user can access another's queries). The idea I had was...
17
by: NeoAlchemy | last post by:
I am starting to find more web pages that are using a query parameters after the JavaScript file. Example can be found at www.opensourcefood.com. Within the source you'll see: <script...
5
by: Just_a_fan | last post by:
I tried to put an "on error" statement in a routine and got the message that I cannot user "on error" and a lamda or query expression in the same routine. Help does not list anything useful for...
13
by: canabatz | last post by:
i got for example this result from data base: user1 user1 user1 user2 user2 user1 user1
7
alpnz
by: alpnz | last post by:
I am trying to access data on a mySQL server, but due to my age and alzheimer's I seem to be overlooking the obvious mistake here. Anyone care to spare a couple of minutes to help. <? $host =...
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
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,...
1
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.