Query to find string only containing certain characters

Hi Experts,

I am trying to clean up a data import, and want to find all records where, in a particular field they only contain spaces and commas in any combination.  

" , " would be found
"smith, john" would not
"    , " would be found
",     ," would be found

The numbers of comma and spaces vary, and records with other data may contain commas and spaces but should be left.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
select * from tablex
where instr([filedName]," , ")>0 or  instr([filedName],"  , ")>0 or  instr([filedName],",    ,")>0
use replace...

where len(replace(replace(column,' ',.''),',',''))=0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rey Obrero (Capricorn1)Commented:
<I am trying to clean up a data import, and want to find all records>
how do want to treat the records found?

as Lowfatspread stated you can use the replace function, but you should be very careful using this (save a copy of table first).

from your example,
how do you want to clean the records with  ",     ," ?
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Norbert2000Author Commented:
Capricorn1 - pretty close!

"Jones , Sara Jane" and a couple of others still slipped through.   The trouble is that the number of spaces and positioning are different in the entries.

Norbert2000Author Commented:
All these entries are just going to be nulled btw
did you try the recommendation of lowfatspread? i think that should work, except that he had an extra '.' in the statement.
where replace(replace(column,' ',''),',','')=0

Open in new window

Rey Obrero (Capricorn1)Commented:
to be able to do it in one pass, you have to know all the combinations.

<All these entries are just going to be nulled btw> as in erased?

create a backup copy first

run this query

Update tableX
set fieldName="" where instr([fieldName]," , ")>0 or  instr([fieldName],"  , ")>0 or  instr([fieldName],",    ,")>0 or  instr([fieldName],"  ,  ")>0 or  instr([fieldName],"   , ")>0
Norbert2000Author Commented:
Thanks - I don't know all combinations so this solution is great.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.