Ruckafella
asked on
Like SQL query in Access error
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*'
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*'
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*";
WHERE Everyone.[Tuition Options] Like "*Option A*";
I run A2003, I just tested that Like clause and it works.
ASKER
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.
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.
ASKER
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?"
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.
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.
Before that you should try a Compact & Repair in Tools
ASKER
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.
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
Ah, glad to see you got it working. Sometimes those little checks can really help bring things to light.
ASKER
Thanks, solution lead me in the correct direction to find the issue with the excel spreadsheet
where everyone like '%option a%'