• If you change the last bit of the case to:

    else case when ((Year(@day) % 4 = 0) and ((Year(@day) % 100 != 0) or (Year(@day) % 400 = 0)))

    you will perform fewer tests.

    With ((A and B) or C), both A and C have to be evaluated even when A is false. When changed to (A and (B or C)), B and C are only evaluated when A is true.