3

在我的表的一列中存储了房屋地址的编号。

不幸的是,我以前的同事不喜欢思考,所以他们制作了类型列varchar并且没有阻止软件上的输入......所以现在我被一堆房屋/公寓数量为“NI”的行困住了、“Not Info”、“Unknown”等,而不是一个有意义的数字......

我只想选择不是数字的行......类似select * from table where CAST(column as int)抛出异常

4

4 回答 4

7

Take a look at IsNumeric, IsInt, IsNumber, you can't use just isnumeric it will return true for - signs and other stuff like that

For example, this returns 1

SELECT ISNUMERIC('2d5'),
       ISNUMERIC('+')
于 2012-12-27T17:56:16.137 回答
3
select * from table where ISNumeric(column)=0 

but it may give false positives .....

于 2012-12-27T17:54:41.300 回答
1

Try this:

SELECT * FROM table WHERE ISNUMERIC(column + 'e0') = 0
于 2012-12-27T17:56:08.820 回答
-1

Create a function that that tries the cast and any other logic that you needs then return 0 if the value doesn't meet your requirements if it succeeds return 1. then use the function in the where clause

于 2012-12-27T17:55:19.273 回答