Actual data:
x
|31345678921|
|56789056789|
|56780345678|
|4567 |
|3456 |
|00678596 |
|03456788453|
|ASA 2344 |
|34565 |
|BBq23 |
|DNF LIMIT |
Required data:
|31345678921|
|56789056789|
|56780345678|
|03456788453|
Advertisement
Answer
One method is:
where actual not like '%[^0-9]%' and
len(actual) = 11
That is, the value has no non-digits and is 11 digits long.
Another method is:
where try_convert(numeric(11,0), actual) between 10000000000 and 99999999999
That is, when converted to a numeric, the range suggests that it is 11 digits.
And a third method is:
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 supports character classes with like
, so you can just like [0-9]
11 times.