variables in SQL syntax - brackets prob

j0se

Registered User.
Local time
Today, 16:15
Joined
Jan 15, 2003
Messages
57
Hi all,

I'm having trouble with my syntax in an SQL statement that passes variables

I'm trying to do this:

SELECT * FROM MyTable WHERE ID >= var1 AND < var2

I'm having probs with the single & double quotation marks that separate the vars from the statement proper

I got something like this:
SQL = "Select * from MyTable Where ID >= ' " & var1 & ' " AND < ' " & var2

which is not correct

If anybody can correct this statement I shall be very pleased :)
 
ID is numeric?

so try:
SQL = "SELECT * FROM MyTable WHERE ID >= " & var1 & " AND ID < " & var2 & ";"


...consider the use of
SQL = "SELECT * FROM MyTable WHERE ID BETWEEN " & var1 & " AND " & var2 & ";"
check the boundaries to make sure BETWEEN is behaving the way you want it to i.e. that BETWEEN 10 AND 20 does what you expect for 10 and for 20

izy
 
thanks

BETWEEN works great!!!

Thanks for your help ;)
 

Users who are viewing this thread

Back
Top Bottom