Forums
This topic is locked
<= and >= filter criteria ...please help!
Posted 01 Nov 2001 14:17:21
1
has voted
01 Nov 2001 14:17:21 Tim Driver posted:
I have a search form with minimum and maximum age text fields and need to return results to reflect that. For example, if a user wants to find people aged between 25 and 30, they put 25 in the 'minimum' box and '30' in the maximum box. To set up the Recordset SQL filter criteria for this, I have written this code:SELECT *
FROM Settings
WHERE Age >= 'MMColParam6' AND Age <= 'MMColParam7'
where MMColParam6 is Request("fmSearchAgeMin" and MMColParam7 is Request("fmSearchAgeMax".
When I hit the Test button in the Recordset window it gives the error "Data type mismatch in criteria expression".
Any ideas anyone? Do I need to convert the form variables into numeric variables before >= and <= operators will work?
Thanks
Tim
Replies
Replied 01 Nov 2001 19:26:38
01 Nov 2001 19:26:38 Viktor Farcic replied:
If Age field is number then remove '' signs, they are used only if field is of text type.
SELECT *
FROM Settings
WHERE Age >= MMColParam6 AND Age <= MMColParam7
SELECT *
FROM Settings
WHERE Age >= MMColParam6 AND Age <= MMColParam7
Replied 02 Nov 2001 12:15:19
02 Nov 2001 12:15:19 Tim Driver replied:
Thanks, it's sorted now.
I have since learnt that you can also use BETWEEN instead of mathematical symbols, ie
SELECT *
FROM Settings
WHERE Age BETWEEN MMColParam6 AND MMColParam7
instead of
SELECT *
FROM Settings
WHERE Age >= MMColParam6 AND Age <= MMColParam7
which is useful to know.
I have since learnt that you can also use BETWEEN instead of mathematical symbols, ie
SELECT *
FROM Settings
WHERE Age BETWEEN MMColParam6 AND MMColParam7
instead of
SELECT *
FROM Settings
WHERE Age >= MMColParam6 AND Age <= MMColParam7
which is useful to know.