1 Reply Latest reply on Aug 15, 2017 1:47 PM by Ben Neville

    How to write an if and right statement

    Alex Martino



      I have a field that I care about the last digit or the last two digits.


      For example ABC07




      I want to extract the number (without the 0) to compare to another number.


      I want to say if the second to last digit is 0, then do Right, 1, otherwise do Right 2.


      How can I write this?

        • 1. Re: How to write an if and right statement
          Ben Neville

          If you cast these to an INT, the leading zero is "lost" anyway, so it shouldn't much matter if it exists.


          If you really wanted to do the logic the way you described, you could choose:

          IF LEFT(RIGHT([Field],2),1) = 0 THEN RIGHT([Field],1) ELSE RIGHT([Field],2) END


          But if you're comparing numbers, I would probably just use: