views:

52

answers:

1

Hi there,

I need an sql query to give me the following:

All the values in a column of type varchar(50) which will NOT convert or will throw an error if cast / converted to an int.

E.g.

row 1: '1'

row 2: '2'

row 3: '3a'

row 4: '4.5'

I need row 3....however there are tens of thousands of rows.

Thanks!

+4  A: 

http://msdn.microsoft.com/en-us/library/aa933213%28SQL.80%29.aspx

e.g.,

SELECT * WHERE ISNUMERIC(column)=1

Edit: Actually, this wouldn't quite cut it if you want precisely int only. Try this instead. If you only want int range, then throw in a range check as well (feeling a bit lazy at this point).

SELECT * 
WHERE 
       ISNUMERIC(column)=1 
       OR (CEILING(CONVERT(float, column))!=FLOOR(CONVERT(float, column)))
hythlodayr
unfortunately that lets float values through, im sorry if my example mislead, but i need to test if convertible to an integer.
andrej351
Yep. Give the second one a whirl.
hythlodayr
Cool thanks, if you change it to ISNUMERIC(column) <> 1 then it catches float values too. Cheers!
andrej351