Search code examples
sqljsl

How to make my code more efficient (beginner :)


can someone suggest a shorter code that does the same?

CASE 
WHEN  {location} LIKE '%00' OR  {location} LIKE  '%010' OR  {location} LIKE '%011' OR  {location} LIKE '%012' OR  {location} LIKE '%013' THEN '1'
WHEN  {location} LIKE '%38' OR  {location} LIKE '%039' OR  {location} LIKE '%040' OR  {location} LIKE '%041' OR  {location} LIKE '%042' OR  {location} LIKE '%043' OR  {location} LIKE '%044' OR  {location} LIKE '%046' OR  {location} LIKE '%047' THEN '2'
ELSE '3' 
END

Solution

  • instead fo several OR you could try using between range

    CASE when substr({location}, -2) ='00' 
      or cast(substr({location}, -2)) AS UNSIGNED )between 10 and 13 then '1'
        when cast(substr({location}, -2)) AS UNSIGNED) between 38 and 47 then '2'
      else '3'
    end