Why isnt this SQL working?

G

Guest

I am trying to use "Like" to return a record containing text in a box on a
form. This wasn't working, so I put the actual value in the query and that
wouldn't work either. I've tried changing the syntax so many times I'm not
sure what is right anymore.

SELECT records FROM records
WHERE (((records.SH)='%9010%'));

The SH field contains strings like "8070, 9010, t-240"

I've tried "%CSTR(Form![form]![text])%", "%" & CSTR(Form![form]![text]) &
"%", and several similar arrangements. If I had hair I would be pulling it
out.

Any help is greatly appreciated.
 
M

Marshall Barton

Ken said:
I am trying to use "Like" to return a record containing text in a box on a
form. This wasn't working, so I put the actual value in the query and that
wouldn't work either. I've tried changing the syntax so many times I'm not
sure what is right anymore.

SELECT records FROM records
WHERE (((records.SH)='%9010%'));

The SH field contains strings like "8070, 9010, t-240"

I've tried "%CSTR(Form![form]![text])%", "%" & CSTR(Form![form]![text]) &
"%", and several similar arrangements. If I had hair I would be pulling it
out.


Something's not right here, you said you want to use Like,
but you're using = instead.

Whether you use % or * depends on the db engine you're
using. For a Jet database, it should be:

WHERE SH LIKE '*9010*
'
 
G

Guest

No, what do the #'s stand for?

I tried that and I get "Data Type Mismatch in criteria expression"

Any other suggestions?

Thanks!

JL said:
Hi Ken,

Try to replace you "%" with "*".

Hope that will work for you.


Ken said:
I am trying to use "Like" to return a record containing text in a box on a
form. This wasn't working, so I put the actual value in the query and that
wouldn't work either. I've tried changing the syntax so many times I'm not
sure what is right anymore.

SELECT records FROM records
WHERE (((records.SH)='%9010%'));

The SH field contains strings like "8070, 9010, t-240"

I've tried "%CSTR(Form![form]![text])%", "%" & CSTR(Form![form]![text]) &
"%", and several similar arrangements. If I had hair I would be pulling it
out.

Any help is greatly appreciated.
 
G

Guest

Hi Ken,

Marshall Barton also said that you have "=" in your query. In "Like", you
do not need it. I did not say replace with "#" (Number Sign). I say replace
with a "*" (Star). In MS Access, the "*" is the wild card.

Hope this clears up.


SMac said:
No, what do the #'s stand for?

I tried that and I get "Data Type Mismatch in criteria expression"

Any other suggestions?

Thanks!

JL said:
Hi Ken,

Try to replace you "%" with "*".

Hope that will work for you.


Ken said:
I am trying to use "Like" to return a record containing text in a box on a
form. This wasn't working, so I put the actual value in the query and that
wouldn't work either. I've tried changing the syntax so many times I'm not
sure what is right anymore.

SELECT records FROM records
WHERE (((records.SH)='%9010%'));

The SH field contains strings like "8070, 9010, t-240"

I've tried "%CSTR(Form![form]![text])%", "%" & CSTR(Form![form]![text]) &
"%", and several similar arrangements. If I had hair I would be pulling it
out.

Any help is greatly appreciated.
 
G

Guest

That was it, I didn't have the = in there, until I wrote the post, but it was
the need for "*". I tried it after the first reply, but I must have has
something still wrong.

Greatly appreciate all the help.

Marshall Barton said:
Ken said:
I am trying to use "Like" to return a record containing text in a box on a
form. This wasn't working, so I put the actual value in the query and that
wouldn't work either. I've tried changing the syntax so many times I'm not
sure what is right anymore.

SELECT records FROM records
WHERE (((records.SH)='%9010%'));

The SH field contains strings like "8070, 9010, t-240"

I've tried "%CSTR(Form![form]![text])%", "%" & CSTR(Form![form]![text]) &
"%", and several similar arrangements. If I had hair I would be pulling it
out.


Something's not right here, you said you want to use Like,
but you're using = instead.

Whether you use % or * depends on the db engine you're
using. For a Jet database, it should be:

WHERE SH LIKE '*9010*
'
 
M

Marshall Barton

Ken said:
That was it, I didn't have the = in there, until I wrote the post, but it was
the need for "*". I tried it after the first reply, but I must have has
something still wrong.


Glad you've got it sorted out.

To avoid confusion in the future, when posting code please
use Copy/Paste instead of retyping it.
 

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