Simple Delete Query

S

SITCFanTN

I have a table that includes the field titled "State". I want to delete all
records in a table except records that have "AZ", "CT" or "NY" in the state
field. I have tried the criteria of =Not "AZ" or"CT or "NY", but I'm not
getting the correct results. I only retain AZ records. Any help you can
provide is appreciated, thank you.
 
D

Dirk Goldgar

SITCFanTN said:
I have a table that includes the field titled "State". I want to delete
all
records in a table except records that have "AZ", "CT" or "NY" in the
state
field. I have tried the criteria of =Not "AZ" or"CT or "NY", but I'm not
getting the correct results. I only retain AZ records. Any help you can
provide is appreciated, thank you.


Try this:

DELETE FROM [YourTableName]
WHERE [State] Not In('AZ', 'CT', 'NY')
 
J

Jerry Whittle

Not "AZ" or Not "CT" or Not "NY"

This is cleaner:

Not In ("AZ", "CT", "NY")

Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.
 
J

John W. Vinson

Not "AZ" or Not "CT" or Not "NY"

Sleepy, Jerry? <g>

That should be "AND" rather than "OR" - "AZ" is in fact Not "NY", so this
criterion will delete all records in the table!
This is cleaner:

Not In ("AZ", "CT", "NY")

Absolutely better.
 
J

Jerry Whittle

Looks like I need a brain reboot. One dope-slap self-applied to the head.

Thanks John!
 

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