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'.
This question is related to
sql
sql-server
sql-function
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
SELECT * FROM Orders where OrderID % 2 = 0;///this is for even numbers
SELECT * FROM Orders where OrderID % 2 != 0;///this is for odd numbers
MOD() function exists in both Oracle and MySQL, but not in SQL Server.
In SQL Server, try this:
SELECT * FROM Orders where OrderID % 2 = 0;
--This is for oracle
SELECT DISTINCT City FROM Station WHERE MOD(Id,2) = 0 ORDER BY City;
Try this:
SELECT DISTINCT city FROM STATION WHERE ID%2=0 ORDER BY CITY;
SELECT * FROM ( SELECT *, Row_Number()
OVER(ORDER BY country_gid) AS sdfg FROM eka_mst_tcountry ) t
WHERE t.country_gid % 2 = 0
Source: Stackoverflow.com