Phoenix Phoenix - 1 year ago 87
SQL Question

Finding even or odd ID values

I was working on a query today which required me to use the following to find all odd number ID values

(ID % 2) <> 0

Can anyone tell me what this is doing? It worked, which is great, but I'd like to know why.

Answer Source

ID % 2 is checking what the remainder is if you divide ID by 2. If you divide an even number by 2 it will always have a remainder of 0. Any other number (odd) will result in a non-zero value. Which is what is checking for.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download