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]%'.