Search code examples
sqlcaseteradatasql-like

sql expression pattern matching


I want to check for a pattern in sql such that if there is anything in that expression (or table cell) other than numeric it should return 1. If that whole cell has only numeric values it should return 0

eq:

case when '200290' like [anything other than numbers]
then 1
else o

Solution

  • In SQL Server, you can use something like (I'm not writing the whole function for you):

    DECLARE @t varchar(100) = '231321321321'
    
    SELECT CASE WHEN PATINDEX('%[^0-9]%', @t) > 0 THEN 1
                ELSE 0 END