Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an sql condition that can look for non integers in a column?

Tags:

Basically I would like a select statement that would function like this

SELECT * FROM table   WHERE column IS NOT INT   

Is there a condition like this or how do you check for non-integers in an nvarchar(10) column?

like image 979
Niklas Avatar asked Apr 26 '11 11:04

Niklas


People also ask

How do I find non numeric values in a column in SQL?

This is the way: SELECT * FROM TABLE_NAME WHERE NOT REGEXP_LIKE(COLUMN_NAME, '^-?[0-9.]+$ '); This also excludes values which contain decimals.

How do you check if a number is integer or not in SQL?

Syntax to check if the value is an integer. select yourColumnName from yourTableName where yourColumnName REGEXP '^-?[0-9]+$'; The query wherein we have used regular expression. This will output only the integer value.


2 Answers

In SQL Server you can do:

SELECT  * FROM    mytable   WHERE   CASE WHEN IsNumeric(mycolumn) = 1 THEN CASE WHEN CAST(mycolumn AS FLOAT) <> CAST(CAST(mycolumn AS FLOAT) AS INT) THEN 1 END ELSE 1 END = 1 
like image 199
Quassnoi Avatar answered Sep 17 '22 17:09

Quassnoi


You could also use

SELECT  * FROM    T  WHERE  C = ''         OR C LIKE '%[^0-9-]%' /*Contains a char other than - or 0-9*/         OR C LIKE '_%-%'  /*Contains the - char other than 1st position*/ 
like image 21
Martin Smith Avatar answered Sep 20 '22 17:09

Martin Smith