Monday, August 17, 2020

HOW TO FETCH ODD/EVEN RECORDS IN SQL SERVER

Here, we will first insert a records into the Employee table and then we will fetch odd and even records from employee table. Please see the below screenshot i.e. adding multiple records in Employee table with insert query:


    FETCH ODD RECORDS: Now, we will first fetch the odd records from Employee table by using query i.e.

    SELECT * FROM EMPLOYEE WHERE ID % 2 != 0 

                                            OR

    SELECT * FROM EMPLOYEE WHERE ID % 2 < > 0

    Please see the below screenshot for further clarification.          

    FETCH EVEN RECORDS: To fetch the even records from Employee table, we will use query i.e.

    SELECT * FROM EMPLOYEE WHERE ID % 2 = 0 

    Please see the below screenshot for further clarification.       

                      

                   - - - - - - Cheers, Happy to Help! - - - - - - 



No comments:

Post a Comment

DIFFERENCE BETWEEN CHAR AND VARCHAR IN SQL SERVER

CHAR:  The  CHAR datatype is a fixed length data type in sql server. It is used to store fixed length type of string data or character strin...