Search code examples
sqlsql-serversql-function

Select Rows with id having even number


I am passing a simple query where I am searching for specific rows where OrderID is an even number

SELECT * 
FROM Orders 
WHERE mod(OrderID,2) = 0;

Error :

Syntax error (missing operator) in query expression 'mod(OrderID,2) = 0'.


Solution

  • You are not using Oracle, so you should be using the modulus operator:

    SELECT * FROM Orders where OrderID % 2 = 0;
    

    The MOD() function exists in Oracle, which is the source of your confusion.

    Have a look at this SO question which discusses your problem.