Reputation: 15
New to SQL.
I am trying to pull all the records where "Customer Number" is a 12-digit number. In the "Customer Number" column, there are only 9 digit or 12 digit numbers. I need only the customers who's "Customer Number" is 12 digits. Seems straight forward but couldn't figure it out.
Thanks
Upvotes: 0
Views: 9752
Reputation: 11
select customer_num from
xx_customers
where length(customer_num)=12;
Length
function can be used in where condition
Upvotes: 1
Reputation: 1269753
You can use len()
/length()
(depending on your database):
select t.*
from t
where len(customer_number) = 12
You can also use like
:
where customer_number like '____________' -- exactly 12 underscores
Upvotes: 0