Using expression builder to write a delete query

presence76

Board Regular
Joined
May 11, 2004
Messages
76
I am using expression builder to write a delete query. I have a table that has a column called batch. In this column are data that look like:


ED20040524I1002
BA20040524DBT1

and so on.

I want to delete anything that does not begin with BA.
Therefore, my query reads

NOT LIKE "BA*"

This does not work and I cannot fiqure out why. I have played with it, trying other values on other fields in the same table and they work fine but not in this field. Any ideas??
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I'm not sure why your query isn't working, but as an alternate way of doing it, try this.

Create a custom field in your query.
Test:Left(batch,2)

Criteria = "BA"
 
Upvote 0
Try typing:
not like "BA*"
in the criteria section of the query builder section.
Your SQL should read something like this:

DELETE Table1.Your_field
FROM Table1
WHERE (((Table1.Your_field) Not Like "BA*"));
 
Upvote 0
What I ended up doing was making the query a select query instead of a delete query. For some reason, ACCESS does not like double negatives.
 
Upvote 0
Here's just a general suggestion, especially when using the QBE Wizard to do things like UPDATE/DELETE queries.

UPDATE and DELETE perform actions on your data. If you're testing, and run them, it will irrevocably change your data. If you delete something you need -- and you can't get it back -- well, it's obvious that's bad.

Always start by building your queries as SELECT queries. Make them work that way first - and look at what shows up. That includes setting your parameters. Only after you have it working (AND SAVED once) do you change the query to a different type, such as your above referenced DELETE query.

Cbrine was correct though. It should have accepted Not Like in the parameter. Sometimes the best thing to do is start the query over. Delete and recreate.

Mike
 
Upvote 0

Forum statistics

Threads
1,221,692
Messages
6,161,351
Members
451,697
Latest member
pedroDH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top