Simple SQL query with Variables

Simple SQL query with Variables

Post by David Warne » Thu, 16 Mar 2000 04:00:00



I'm really new with access and web design.  I'm trying to create a dynamic
query page to query our helpdesk database.  There is a drop down box that
allows the user to specify using a 'AND' or 'OR' statement in the SQL query.
But I can't get it to work.  It is some kind of syntax error that I can't
figure out.  Here is my Where clause:

WHERE "%%field1%%" = '%%string1%%' '%%operator%%' "%%field2%%" =
'%%string2%%'

And I get this error message:

Database Error: [Microsoft][ODBC Microsoft Access Driver] Syntax error
(missing operator) in query expression '[PROBTYPE] = 'pc' 'AND' [TECHID] =
'dw''.

If I litteraly use "AND" (with no quotes) instead of '%%operator%%' it
works, so I'm thinking its something wrong with the quotes or something.

Any help would be greatly appreciated.  Thanks!

Dave

 
 
 

Simple SQL query with Variables

Post by Brian Wallac » Thu, 16 Mar 2000 04:00:00


Can you use an if then statement and create two SQL statements one for AND
one for OR
Can you take the ' off the and, it looks like it is leaving it on them in
the error message below...

Brian


Quote:> I'm really new with access and web design.  I'm trying to create a dynamic
> query page to query our helpdesk database.  There is a drop down box that
> allows the user to specify using a 'AND' or 'OR' statement in the SQL
query.
> But I can't get it to work.  It is some kind of syntax error that I can't
> figure out.  Here is my Where clause:

> WHERE "%%field1%%" = '%%string1%%' '%%operator%%' "%%field2%%" =
> '%%string2%%'

> And I get this error message:

> Database Error: [Microsoft][ODBC Microsoft Access Driver] Syntax error
> (missing operator) in query expression '[PROBTYPE] = 'pc' 'AND' [TECHID] =
> 'dw''.

> If I litteraly use "AND" (with no quotes) instead of '%%operator%%' it
> works, so I'm thinking its something wrong with the quotes or something.

> Any help would be greatly appreciated.  Thanks!

> Dave


 
 
 

Simple SQL query with Variables

Post by David Warne » Fri, 17 Mar 2000 04:00:00


Thanks for replying.  I tried taking the ' off the AND, and it didn't work.
But I will try the if statement.  Thanks again.

Dave


> Can you use an if then statement and create two SQL statements one for AND
> one for OR
> Can you take the ' off the and, it looks like it is leaving it on them in
> the error message below...

> Brian



> > I'm really new with access and web design.  I'm trying to create a
dynamic
> > query page to query our helpdesk database.  There is a drop down box
that
> > allows the user to specify using a 'AND' or 'OR' statement in the SQL
> query.
> > But I can't get it to work.  It is some kind of syntax error that I
can't
> > figure out.  Here is my Where clause:

> > WHERE "%%field1%%" = '%%string1%%' '%%operator%%' "%%field2%%" =
> > '%%string2%%'

> > And I get this error message:

> > Database Error: [Microsoft][ODBC Microsoft Access Driver] Syntax error
> > (missing operator) in query expression '[PROBTYPE] = 'pc' 'AND' [TECHID]
=
> > 'dw''.

> > If I litteraly use "AND" (with no quotes) instead of '%%operator%%' it
> > works, so I'm thinking its something wrong with the quotes or something.

> > Any help would be greatly appreciated.  Thanks!

> > Dave

 
 
 

1. Simple SQL query is very, very slow within Access.

I have two tables and I wish to return the items in table1 that do not
appear in table2. Both tables have but one row that stores an integer
value. I wrote the following Query:

SELECT [Table1].intValue
FROM [Table1]
WHERE [Table1].intValue Not In (Select intValueTbl2 from  [Table2]);

Table1 has 400 rows
Table2 has 3000 rows

This Query works well if Table1 and Table2 only have but a few records
(i.e. under 100). If they have, as in my example, a few thousand
records, the query is unbelievable slow. It takes 5++ minutes to process
the query on a P3 500. Is there a better way in Access to create the
query or can I speed it up somehow?

Would anyone know why Access is having so many problems with such a
simple query?

Thanks,
Robert

2. Importing data from Access 97 into Excel 2.0

3. MS Access: Need help with Simple SQL query

4. Adding auto text depending on diagnost

5. Simple Query/SQL Question !

6. #N/A remove error message

7. help with simple(I think!) sql query

8. defining a Global variable

9. Simple SQL query?

10. SQL simple query fails

11. Simple SQL query - please help

12. correct SQL for a simple Query?

13. MS Access: Need help with Simple SQL query