sqlparsingintegerint

how to parse ONLY integer values in SQL


I want to be able to parse only integer values from a column in a database such that my query looks like the following:

SELECT x
FROM database
WHERE x is like int

where X is a column in a database that would have the following values:

x
TRUE
FALSE
8.9
234
TY09B-XYZ

and my query would only return

x
8.9
234

thanks!


Solution

  • Assuming SQLServer, and assuming you mean numbers as opposed to just integers (8.9 is not an integer)

    SELECT x
    FROM table
    WHERE isnumeric(x) = 1
    

    More information on MSDN: https://msdn.microsoft.com/en-us/library/ms186272.aspx