Todd
Todd

Reputation: 1822

Checking for numeric value in field + 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

Upvotes: 10

Views: 38835

Answers (3)

tanerkay
tanerkay

Reputation: 3930

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

Upvotes: 23

gbn
gbn

Reputation: 432639

A simple LIKE to find any number will suffice...

...WHERE LIKE '%[0-9]%'

Upvotes: 10

Gabriel McAdams
Gabriel McAdams

Reputation: 58293

select ISNUMERIC(data)

Upvotes: 3

Related Questions