I have a column that contains numbers and other string values (like \"?\", \"???\", etc.)
Is it possible to add an \"is number\" condition to the where clause in SQL
To test whether the column contains exclusively an integer with no other alphanumeric characters, use:
NOT myColumn GLOB '*[^0-9]*' AND myColumn LIKE '_%'
I.e., we test whether the column contains anything else than a digit and invert the result. Additionally we test whether it contains at least one character.
Note that GLOB '*[0-9]*'
will find digits nested between other characters as well. The function typeof()
will return 'text'
for a column typed as TEXT, even if the text represents a number. As @rayzinnz mentioned, the abs()
function is not reliable as well.
SELECT *
FROM mytable
WHERE columnNumeric GLOB '*[0-9]*'
select * from mytable where abs(mycolumn) <> 0.0 or mycolumn = '0'
http://sqlfiddle.com/#!5/f1081/2
Based on this answer