-3

I'm using the dbvisualizer SQL statement and am trying to search a field for whether it has letters and numbers, or just one or the other. Is this possible to do in a simple manner? Currently I'm just checking each one individually like so:

case when card_address like '%0%'
       or card_address like '%1%'
       or card_address like '%2%'
       or card_address like '%3%'
       or card_address like '%4%'
       or card_address like '%5%'
       or card_address like '%6%'
       or card_address like '%7%'
       or card_address like '%8%'
       or card_address like '%9%'
     then 'True' else 'False' end as numbers_in_address
  • 2
    DBVisualizer is just a SQL client that connects to a database server. Which database product (server) are you using (connecting to)? The SQL client has no influence on what the database itself can do or which feature it supports –  Jan 10 '18 at 21:14
  • Please indicate which database you are using (by editing the tags), because the answer is database-dependent. In some databases your code is the best you can hope for, but others support regex. – Bohemian Jan 10 '18 at 21:55

1 Answers1

0

In MYSQL you can do it with Regular Expression Operators

case 
  when card_address REGEXP '[0-9]' then 'True' 
  else 'False' 
end as numbers_in_address

In SQLSERVER you can use pattern in LIKE

 case 
      when card_address  LIKE '%[0-9]%' then 'True' 
      else 'False' 
end as numbers_in_address
sumit
  • 15,003
  • 12
  • 69
  • 110