Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select only string with number SQL Server

I need select only strings in my table, but this table has numbers and strings together.

Ex:

ID Name
1  Jacke11
2  Andre
3  Rodrigo11
4  55555

My select need return only Ids: 1, 2, 3.

Thanks

like image 539
soamazing Avatar asked Jan 12 '12 18:01

soamazing


1 Answers

As an alternative to Joe's very fine ISNUMERIC solution, you can use PATINDEX to make sure you have an alpha character:

SELECT ID
    FROM YourTable
    WHERE PATINDEX('%[a-z]%', name) > 0

This may be slightly faster since it will stop searching the string as soon as it gets to the first alpha character.

like image 151
JNK Avatar answered Nov 15 '22 18:11

JNK