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'.
How do you check if a number is even in SQL Server? 10 Answers Use the modulus operator n % 2 . It returns 0 if the number is even, and 1 if the number is odd.
To select duplicate values, you need to create groups of rows with the same values and then select the groups with counts greater than one. You can achieve that by using GROUP BY and a HAVING clause.
To find and return the records with the odd or even values, the most simple way is to check the remainder when we divide the column value by 2. When the remainder is 0, that's an even number, otherwise, that's an odd number.
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.
SELECT * FROM Orders where OrderID % 2 = 0;///this is for even numbers SELECT * FROM Orders where OrderID % 2 != 0;///this is for odd numbers
Sql Server we can use %
select * from orders where ID % 2 = 0;
This can be used in both Mysql and oracle. It is more affection to use mod function that %.
select * from orders where mod(ID,2) = 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With