What's wrong with my SQL stmt?

G

Gator

I get the error...
Syntax error (missing operator) in query expression "[field6] = "18708960"
or where [field6] = "19995601"
or where [field6] = "17726948"

here is my SQL stmt....
select [field3],[field6],[field7],[field8],[field11],[field12]
from [2007Q1]
where [field6] = "18708960"
or where [field6] = "19995601"
or where [field6] = "17726948"

UNION select [field3],[field6],[field7],[field8],[field11],[field12]
from [2007Q2]
where [field6] = "18708960"
or where [field6] = "19995601"
or where [field6] = "17726948"

UNION select [field3],[field6],[field7],[field8],[field11],[field12]
from [2007Q3]
where [field6] = "18708960"
or where [field6] = "19995601"
or where [field6] = "17726948"

UNION select [field3],[field6],[field7],[field8],[field11],[field12]
from [2007Q4]
where [field6] = "18708960"
or where [field6] = "19995601"
or where [field6] = "17726948"

UNION select [field3],[field6],[field7],[field8],[field11],[field12]
from [2008Q1]
where [field6] = "18708960"
or where [field6] = "19995601"
or where [field6] = "17726948"

UNION select [field3],[field6],[field7],[field8],[field11],[field12]
from [2008Q2]
where [field6] = "18708960"
or where [field6] = "19995601"
or where [field6] = "17726948"

UNION select [field3],[field6],[field7],[field8],[field11],[field12]
from [2008Q3]
where [field6] = "18708960"
or where [field6] = "19995601"
or where [field6] = "17726948";
 
B

Bob Barrows

Gator said:
I get the error...
Syntax error (missing operator) in query expression "[field6] =
"18708960" or where [field6] = "19995601"
or where [field6] = "17726948"

here is my SQL stmt....
select [field3],[field6],[field7],[field8],[field11],[field12]
from [2007Q1]
where [field6] = "18708960"
or where [field6] = "19995601"
or where [field6] = "17726948"
You can only use the word "where" once per sql statement:

select [field3],[field6],[field7],[field8],[field11],[field12]
from [2007Q1]
where [field6] = "18708960"
or [field6] = "19995601"
or [field6] = "17726948"


An easier way to write this is to use IN()

where [field6] IN ("18708960","19995601","17726948")
 
G

Gator

Now I get the error...
Data type mismatch in criteria expression.

Here is SQL...(it has changed, but same principle)

select [field1], [field2]
from table2
where [field1] IN ("1","2")

UNION select [field1], [field2]
from table3
where [field1] IN ("1","2");


Bob Barrows said:
Gator said:
I get the error...
Syntax error (missing operator) in query expression "[field6] =
"18708960" or where [field6] = "19995601"
or where [field6] = "17726948"

here is my SQL stmt....
select [field3],[field6],[field7],[field8],[field11],[field12]
from [2007Q1]
where [field6] = "18708960"
or where [field6] = "19995601"
or where [field6] = "17726948"
You can only use the word "where" once per sql statement:

select [field3],[field6],[field7],[field8],[field11],[field12]
from [2007Q1]
where [field6] = "18708960"
or [field6] = "19995601"
or [field6] = "17726948"


An easier way to write this is to use IN()

where [field6] IN ("18708960","19995601","17726948")
 
G

Gator

I got it...I was using quotes around number data type...a no no

Gator said:
Now I get the error...
Data type mismatch in criteria expression.

Here is SQL...(it has changed, but same principle)

select [field1], [field2]
from table2
where [field1] IN ("1","2")

UNION select [field1], [field2]
from table3
where [field1] IN ("1","2");


Bob Barrows said:
Gator said:
I get the error...
Syntax error (missing operator) in query expression "[field6] =
"18708960" or where [field6] = "19995601"
or where [field6] = "17726948"

here is my SQL stmt....
select [field3],[field6],[field7],[field8],[field11],[field12]
from [2007Q1]
where [field6] = "18708960"
or where [field6] = "19995601"
or where [field6] = "17726948"
You can only use the word "where" once per sql statement:

select [field3],[field6],[field7],[field8],[field11],[field12]
from [2007Q1]
where [field6] = "18708960"
or [field6] = "19995601"
or [field6] = "17726948"


An easier way to write this is to use IN()

where [field6] IN ("18708960","19995601","17726948")
 
J

John Spencer

Is your field 1 a text field or a number field? If it is a number field
then you need to drop the quotes around 1 and 2 in your where clause.

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================

Now I get the error...
Data type mismatch in criteria expression.

Here is SQL...(it has changed, but same principle)

select [field1], [field2]
from table2
where [field1] IN ("1","2")

UNION select [field1], [field2]
from table3
where [field1] IN ("1","2");


Bob Barrows said:
Gator said:
I get the error...
Syntax error (missing operator) in query expression "[field6] =
"18708960" or where [field6] = "19995601"
or where [field6] = "17726948"

here is my SQL stmt....
select [field3],[field6],[field7],[field8],[field11],[field12]
from [2007Q1]
where [field6] = "18708960"
or where [field6] = "19995601"
or where [field6] = "17726948"
You can only use the word "where" once per sql statement:

select [field3],[field6],[field7],[field8],[field11],[field12]
from [2007Q1]
where [field6] = "18708960"
or [field6] = "19995601"
or [field6] = "17726948"


An easier way to write this is to use IN()

where [field6] IN ("18708960","19995601","17726948")
 
J

John W. Vinson

Now I get the error...
Data type mismatch in criteria expression.

Here is SQL...(it has changed, but same principle)

select [field1], [field2]
from table2
where [field1] IN ("1","2")

UNION select [field1], [field2]
from table3
where [field1] IN ("1","2");

Suggests that Field1 is a Number or Currency datatype. If so get rid of the
quotes; they are appropriate only for Text datatype fields.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top