0

I'm trying to write case when which checks if specific column values are containing certain logic.

    CASE
        WHEN 111 AND ((LENGTH(222) != 10) OR
             (LENGTH(222) = 10 AND NOT ((
             222 RLIKE '[0-9]') OR (222 RLIKE '[a-zA-Z]'))
             OR 222 RLIKE '[^a-zA-Z0-9]' ))
        THEN 1
        ELSE 0

I'm stuck when to assign 1 for values that have length = 10 and only digits or text.

For example '0000000000' has 10 marks and only digits but the logic assigns 0 to it. The aim is to assign for it then '1' value

Any other entries that have 10 marks and only text or integer should be considered as assigned value 1

  • Add a tag for the dbms you're using, to get accurate attention. (Several product specific functions used above.) – jarlh Aug 14 '23 at 14:20
  • `RLIKE '[0-9]'` means it is exactly 1 digit. I think you want `RLIKE '[0-9]+'`, which means 1 *or more* digits. – Bohemian Aug 15 '23 at 06:14
  • @Bohemian thats interesting thing to know, thanks! I ve divided code into 2 WHEN statements, but i' m still interested how could i achieve it with only 1 WHEN – Łukasz Orzechowski Aug 16 '23 at 06:41

0 Answers0