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?
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?
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
An expression of non-boolean type specified in a context where a condition is expected, near 'END'.
–
Fungosity 1e4
or 2d6
) –
Meditate 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
to cover all cases would likely make it a fair bit more convoluted! –
Bassarisk -ve
integers. –
Bassarisk This is so weird
SELECT * FROM TABLE WHERE Period_Year > 1900 AND Period_Month BETWEEN 1 AND 12
Fixed the problem.
the database has no value that are less or eqeul to 1900 and it has no months NOT BETWEEN 1 OR 12.
I also did a SELECT DISTINCT ISDATE(CONCAT( Period_Year,'/',Period_Month,'/', 1)) FROM TABLE
I GOT A TRUE i.e 1 BACK
NO FALSE i.e 0 WHERE RETURNED
only 1 row with 1 for true
Even when I do SELECT * FROM TABLE WHERE Period_Year > 1
this fixes the problem
© 2022 - 2024 — McMap. All rights reserved.
'42.0'
considered an integer? – Janice42.0
and-15
it would probably be of help to others with similar questions. – Fungosity42.0
,-15
and1E8
. – Janice