0

I have customer numbers some of which are longer than 8 digits. How can I flag them so they are not counted?

I tried the following:

SELECT 
t1.updte_user as staff_number,
(CASE WHEN (CAST(t1.updte_user) AS INT ) Integer not null check 
((CAST(t1.updte_user)AS INT) between 0 and 99999999 THEN  1 else 0 ) end as  
TRUE_STAFF
from old as t1;

What do I need to change?

Anna
  • 444
  • 1
  • 5
  • 23

2 Answers2

1

How about this?

select staff_number, 
       (case when t1.updte_user > 100000000 then 0 else 1 end)
from old;

If the value is a string, then just use length():

select staff_number,
       (case when length(t1.updte_user) > 8 then 0 else 1 end)
from old;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

You can try below

SELECT 
t1.updte_user as staff_number,
CASE WHEN length((CAST(t1.updte_user AS string))>8 then 0 else 1 as  
TRUE_STAFF
from old as t1;
Fahmi
  • 37,315
  • 5
  • 22
  • 31