user3271955 user3271955 - 1 year ago 54
SQL Question

Select numbers with commas

I want to select all rows, which are numbers and commas, nothing else.
For example these varchars should be returned by select:


Have you any idea how to do it?

Answer Source

If I understand correctly:

where col not like '%[^,0-9]%'

If you want to prevent two commas from being in a row:

where col not like '%[^,0-9]%' and
      col not like '%,,%'

I feel the need to add that storing numbers in comma-delimited lists is a really bad idea.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download