是否有可以在列中查找非整数的 sql 条件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5789422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 10:19:21  来源:igfitidea点击:

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

sqlsql-serverconditional-statements

提问by Niklas

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?

是否有这样的条件,或者您如何检查 nvarchar(10) 列中的非整数?

采纳答案by Quassnoi

In SQL Serveryou can do:

SQL Server你可以这样做:

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

回答by Martin Smith

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*/