I want to determine if a value is integer (like TryParse
in .NET). Unfortunatelly ISNUMERIC
does not fit me because I want to parse only integers and not every kind of number. Is there such thing as ISINT
or something?
Here is some code to make things clear. If MY_FIELD
is not int, this code would fail:
SELECT @MY_VAR = CAST(MY_FIELD AS INT)
FROM MY_TABLE
WHERE MY_OTHER_FIELD = 'MY_FILTER'
Thank you
That is probably the simplest solution. Unless your
MY_FIELD
contains .00 or something of that sort. In which case, cast it to a float to remove any trailing .00sI am not a Pro in SQL but what about checking if it is devideable by 1 ? For me it does the job.
This work around with IsNumeric function will work:
select * from A where ISNUMERIC(x) =1 and X not like '%.%'
or Use
select * from A where x not like '%[^0-9]%'
I think that there is something wrong with your database design. I think it is a really bad idea to mix varchar and numbers in one column? What is the reason for that?
Of course you can check if there are any chars other than [0-9], but imagine you have a 1m rows in table and your are checking every row. I think it won't work well.
Anyway if you really want to do it I suggest doing it on the client side.
I have a feeling doing it this way is the work of satan, but as an alternative:
How about a TRY - CATCH?
This works, though only in SQL Server 2008 and up.