Solved

Like SQL query in Access error

Posted on 2011-03-23
14
726 Views
Last Modified: 2012-06-21
Hello experts,

I'm having issues trying to run a like query in MS Access.  When I run the query it continues to give me an "Unknown" error.  The table that I'm querying from is a linked to an excel spreadsheet.  I'm running the query in Access through the query module.  Please help!  

SELECT Everyone.[First Name], Everyone.[Last Name], Everyone.[Entering Grade], Everyone.[Parent/Guardian Name], Everyone.[Tuition Options]
FROM Everyone
WHERE Everyone.[Tuition Options] Like '*Option A*'
0
Comment
Question by:Ruckafella
  • 6
  • 5
  • 3
14 Comments
 
LVL 7

Expert Comment

by:TheTull
ID: 35199987
Have you tried replacing the * characters with %?  I know at least in T-SQL the syntax has you use %, so like this:

where everyone like '%option a%'
0
 
LVL 44

Expert Comment

by:GRayL
ID: 35200546
That won't work in Access.  Just to make sure all spelling is correct, run the query without the WHERE clause.  If it returns records you are good to go.  Now replace the WHERE clause  with:

WHERE Everyone.[Tuition Options] Like "*Option A*";
0
 
LVL 44

Expert Comment

by:GRayL
ID: 35200587
I run A2003, I just tested that Like clause and it works.  
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:Ruckafella
ID: 35201036
GRayL,

I'm running Access 2007, and it still didnt work.  I erased the WHERE clause and the query returned all rows.  I added an equal WHERE clause and the query returned the  appropriate records.  Its just when I run the LIKE query that everything goes wrong.  I tried your query and it still gives me the "Unknown" error.
0
 

Author Comment

by:Ruckafella
ID: 35201065
More specifically, what happens is that it will return the correct records and display for about two seconds before the "Unknown" error pops up.  After the Unknown error comes, all the returned values display as "#Name?"
0
 
LVL 44

Expert Comment

by:GRayL
ID: 35201315
then I suggest your db is 'busted'.

Try creating a new database, and import all the objects from the old one into the new one - use File, Get External Data, Import, and follow the Wizard.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 35201326
Before that you should try a Compact & Repair in Tools
0
 

Author Comment

by:Ruckafella
ID: 35202120
Compact and Repair didnt do anything to help.  I dont think the database is "busted".  Every other query I run works fine, except the LIKE.  Do you think it may have something to do linked tables?  I would think I should be able to query a linked table.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 35202200
Linked to what  - SQL Server?  If so, because the table is linked, SQL Server is providing the link with all the data and Jet should be able to apply the link criteria as if it were an Access table - I think!
0
 
LVL 7

Accepted Solution

by:
TheTull earned 500 total points
ID: 35202379
If you try selecting just the top 5 records or so then, do they come back ok before it gets a chance to crap out on you?  This sounds like some bug where Access can't handle using the LIKE function when linking to Excel.
0
 

Assisted Solution

by:Ruckafella
Ruckafella earned 0 total points
ID: 35207167
TheTull,

It looks like you're on to something there.  When I do a Top 5 query with the exact same WHERE clause, it works fine.  Where do you think the problem is?
0
 

Author Comment

by:Ruckafella
ID: 35207323
Thanks for the hint to use the Top select query.  I was able to locate records that were in the excel spreadsheet that were causing problems.  The was data in excel that was too long for access to handle and this is where there error was coming from.
0
 
LVL 7

Expert Comment

by:TheTull
ID: 35208062
Ah, glad to see you got it working.  Sometimes those little checks can really help bring things to light.
0
 

Author Closing Comment

by:Ruckafella
ID: 35239057
Thanks, solution lead me in the correct direction to find the issue with the excel spreadsheet
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question