SQL : select when a character occurs more than once in a column

Viewed 2187

I have a select statement

select * from B2B_CardTechCards
        where Field NOT LIKE '%-%'

I only want to select the cells that has more than one occurrence of "-" in it. if it occurred once I don't need it.

2 Answers

Simply search for two of them:

select * from B2B_CardTechCards
where Field LIKE '%-%-%'

You can find the count of '-' in Field column by using

(len(Field) - len(replace(Field, '-', '')))

Now we can select rows that has the above count value more than one

select * 
from B2B_CardTechCards
where  (len(Field) - len(replace(Field, '-', ''))) > 1
Related