Use the modulus operator %
. It returns the remainder from division. 1 % 2
is 1, 2 % 2
is 0, 3 % 2
is 1... so if x % 2
is true it is odd.
Then you can use a case
to turn this into 'odd' or 'even'.
select *, case when EmpID % 2 then 'odd' else 'even' endfrom Employees
Or you can select only the odd rows.
select *from Employeeswhere EmpID % 2
Or the even rows.
select *from Employeeswhere not EmpID % 2