How to detect if a string contains at least a number?

后端 未结 4 1984
天命终不由人
天命终不由人 2020-12-05 04:06

How to detect if a string contains at least a number (digit) in SQL server 2005?

相关标签:
4条回答
  • 2020-12-05 04:16
    DECLARE @str AS VARCHAR(50)
    SET @str = 'PONIES!!...pon1es!!...p0n1es!!'
    
    IF PATINDEX('%[0-9]%', @str) > 0
       PRINT 'YES, The string has numbers'
    ELSE
       PRINT 'NO, The string does not have numbers' 
    
    0 讨论(0)
  • 2020-12-05 04:26

    Use this:

    SELECT * FROM Table WHERE Column LIKE '%[0-9]%'
    

    MSDN - LIKE (Transact-SQL)

    0 讨论(0)
  • 2020-12-05 04:38

    The simplest method is to use LIKE:

    SELECT CASE WHEN 'FDAJLK' LIKE '%[0-9]%' THEN 'True' ELSE 'False' END;  -- False
    SELECT CASE WHEN 'FDAJ1K' LIKE '%[0-9]%' THEN 'True' ELSE 'False' END;  -- True
    
    0 讨论(0)
  • 2020-12-05 04:38
    1. You could use CLR based UDFs or do a CONTAINS query using all the digits on the search column.
    0 讨论(0)
提交回复
热议问题