仅返回11位数字值的SQL查询

仅返回11位数字值的SQL查询,sql,sql-server,Sql,Sql Server,实际数据: |31345678921| |56789056789| |56780345678| |4567 | |3456 | |00678596 | |03456788453| |ASA 2344 | |34565 | |BBq23 | |DNF LIMIT | 所需数据: |31345678921| |56789056789| |56780345678| |03456788453| 一种方法是: where actual not li

实际数据:

|31345678921|
|56789056789|
|56780345678|
|4567       |
|3456       |
|00678596   |
|03456788453|
|ASA 2344   |
|34565      |
|BBq23      |
|DNF LIMIT  |
所需数据:

|31345678921|
|56789056789|
|56780345678|
|03456788453|
一种方法是:

where actual not like '%[^0-9]%' and
      len(actual) = 11
where try_convert(numeric(11,0), actual) between 10000000000 and 99999999999
where actual like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
也就是说,该值没有非数字,长度为11位

另一种方法是:

where actual not like '%[^0-9]%' and
      len(actual) = 11
where try_convert(numeric(11,0), actual) between 10000000000 and 99999999999
where actual like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
也就是说,当转换为数字时,范围表示为11位

第三种方法是:

where actual not like '%[^0-9]%' and
      len(actual) = 11
where try_convert(numeric(11,0), actual) between 10000000000 and 99999999999
where actual like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'

SQL Server支持使用like的字符类,因此您可以使用like[0-9]11次。

我不知道为什么这个问题会被解决。这似乎很清楚。