Solved

Like SQL query in Access error

Posted on 2011-03-23
14
722 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
 

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now