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

I have a select statement

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

I only want to select cells that have more than one occurrence of "-". if this happened, when I do not need it.

+4
source share
2 answers

Just search for two of them:

select * from B2B_CardTechCards
where Field LIKE '%-%-%'
+6
source

You can find the counter '-'in the column Fieldusing

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

Now we can select rows with the above account value of more than one

select * 
from B2B_CardTechCards
where  (len(Field) - len(replace(Field, '-', ''))) > 1
+2
source

Source: https://habr.com/ru/post/1688950/


All Articles