John's Brain Dump

All the technical gyrations I go through to build software, so I don't forget them and others can benefit from them.

Receive Email Updates

SQL Trick: Finding Integers in Character Columns

Q: What WHERE condition do you use to find all values in a column that contain only numbers? (No decimal points, no minus signs, just 0-9.

A: [column name ] NOT LIKE '%[^0-9]%'

This is the kind of thing that I'll forget a year from now when I need it again.

UPDATE: 7/11/06

I ran into the need for this again, and I thought I should note that this technique can be used to check that a column contains only characters from any subset, not just numbers. I just used it to verify U.S. Bankruptcy case numbers, which contain only numbers and dashes. My search condition was [CaseNo] NOT LIKE '%[^-0-9]%'.

Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted: May 26 2006, 07:38 PM by John | with no comments
Filed under: ,
Leave a Comment

(required) 

(required) 

(optional)

(required)