Search code examples
sqlsql-serverstringcharacterletter

Find 3 in a row letters


I need to find if one field contain 3 letters in a row:
Examples:

123abv31231 - Correct
abc12314121 - Correct
asdsadsad12 - Correct
98381233abc - Correct
123123ab123 - Not Correct

Doesn't matter where is the 3 characters. It's only matter they must be at least 3 in a row.
I'm using SQL Server


Solution

  • With the operator LIKE:

    select * from tablename
    where col like '%[a-z][a-z][a-z]%'
    

    See the demo.
    Results:

    > | col         |
    > | :---------- |
    > | 123abv31231 |
    > | abc12314121 |
    > | asdsadsad12 |
    > | 98381233abc |