SQL Server modulo operator to find even numbers

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
7 replies · 3K views
Science Advisor
Homework Helper
Messages
7,835
Reaction score
13,160
Hi,
I am trying to find all the even numbers in [FieldName] in SQL Server.

My query is : SELECT [FieldName] FROM Table WHERE [FieldName] % 2 =0 ;

I only get an error message . ( I am using SQL Zoo, since I don't have SQL server available at the moment.

Only message I get is that the query is incorrect. I am trying to avoid using T-Sql, variables, etc.
 
Physics news on Phys.org
Last edited:
  • Like
Likes   Reactions: WWGD
Thanks, Jedi, the strange thing is that the query actually runs , but returns incorrect results.
 
Could it be evaluating the query as?
SQL:
SELECT [FieldName] FROM Table WHERE [FieldName]  =0 ;

where the %2 has been removed.
 
jedishrfu said:
Could it be evaluating the query as?
SQL:
SELECT [FieldName] FROM Table WHERE [FieldName]  =0 ;

where the %2 has been removed.
I don't think so, since [FieldName] is the primary key. There may be a bug in the server or the (client) computer.
 
Last edited:
WWGD said:
I don't think so, since [FieldName] is the primary key. There may be a bug in the server or the (client) computer.
Thanks for the effort, though, a tough one.