使用 SQL 检查列是否包含文本

2021-09-10 00:00:00 sql tsql sql-server

我有一个名为 studentID 的列,但我有 数百万 条记录,并且应用程序以某种方式在其中输入了一些任意文本列.

I have a column which is called studentID, but I have millions of records and somehow the application has input some arbitrary text in the column.

我如何搜索:

SELECT *
  FROM STUDENTS
 WHERE STUDENTID CONTAINS TEXT

推荐答案

将数据库建模问题放在一边.我觉得你可以试试

Leaving database modeling issues aside. I think you can try

SELECT * FROM STUDENTS WHERE ISNUMERIC(STUDENTID) = 0

但是 ISNUMERIC 对任何看起来像数字的值返回 1,包括 -1.0e5

But ISNUMERIC returns 1 for any value that seems numeric including things like -1.0e5

如果您想排除纯数字的学生 ID,请尝试类似

If you want to exclude digit-only studentids, try something like

SELECT * FROM STUDENTS WHERE STUDENTID LIKE '%[^0-9]%'

相关文章