Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking for numeric value in field + SQL Server

Tags:

sql-server

What would be the most efficient way to check for numbers in a field that would contain a few letters? I would like to do this if the where statement as possible.

The data would look something like this:

3833N4323 32N907654 5W5840904

like image 624
Todd Avatar asked Jan 11 '10 22:01

Todd


1 Answers

Checking for at least one number in a field (corrected):

WHERE PATINDEX('%[0-9]%', field) != 0

Checking for only numbers in a field:

WHERE TRY_CONVERT(field AS int) IS NOT NULL
like image 64
tanerkay Avatar answered Oct 21 '22 21:10

tanerkay