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.  

i.e.
" , " 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.

Thanks.
LVL 1
Norbert2000Asked:
Who is Participating?
 
LowfatspreadConnect With a Mentor Commented:
use replace...

where len(replace(replace(column,' ',.''),',',''))=0
0
 
Rey Obrero (Capricorn1)Commented:
select * from tablex
where instr([filedName]," , ")>0 or  instr([filedName],"  , ")>0 or  instr([filedName],",    ,")>0
0
 
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  ",     ," ?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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.

Norb.
0
 
Norbert2000Author Commented:
All these entries are just going to be nulled btw
0
 
ee_rleeConnect With a Mentor Commented:
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

0
 
Rey Obrero (Capricorn1)Commented:
Norbert2000,
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
0
 
Norbert2000Author Commented:
Thanks - I don't know all combinations so this solution is great.
0
All Courses

From novice to tech pro — start learning today.