how to get even numbers in sql

    How to Get Even Numbers in SQL

    Table of Contents

    The simplest way is to check the remainder value. when we divide the column value by 2 when the remainder is 0 means that’s an even number otherwise it’s called an Odd number.

    Syntax:

    We are using the MOD function to check the remainder values but the MS SQL server doesn’t have a MOD function so we are using % percentage.

    Select  * from table name where mod(column_name,2)=0

    or(SQL Server)

    Select  * from table name where column_name%2=0(Even number)

    Select  * from table name where column_name%2<>0(Odd  number)

    How to Get Even Numbers in SQL

    Let’s do this step by step

    1. First we need to create a table to check the even number or odd number.

    Table name: Employee master

    2. Now we have inserted the data into the table.

    3. Which column do you want to need the even number? You have specified that column name in the where condition. To find rows where a specified column has even values.

         SELECT * FROM EMPLOYEEMASTER WHERE Department_id%2 = 0

    4. To find rows where a specified column has odd values.

       SELECT * FROM EMPLOYEEMASTER WHERE Department_id%2 <> 0

    Conclusion

    I hope you found this article about How to get Even Numbers in SQL.

    Now I’d like to hear what you have to say:

    What topic i would like to cover in my future

    Let me know by leaving a comment below.

    You can check my previous blog which is about Which one of the following sorts of rows in SQL is helpful

    Sign up now to receive our monthly newsletter.
    We promise to not use your email for spam!

    Leave a comment on this post

    Latest Posts