Embarrassingly Simple SQL Server query: List Even numbers in....

Click For Summary

Discussion Overview

The discussion revolves around a SQL Server query intended to retrieve even numbers from a specified field in a database. Participants explore potential issues with the query syntax and execution, particularly in the context of using SQL Zoo instead of a direct SQL Server environment.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant shares their SQL query: SELECT [FieldName] FROM Table WHERE [FieldName] % 2 = 0, but encounters an error message while using SQL Zoo.
  • Another participant suggests using the mod function as an alternative to the % operator, referencing MySQL documentation.
  • A different participant raises the possibility that the % character may conflict with script parameters in Windows, proposing the mod function as a better choice.
  • One participant notes that the query runs but returns incorrect results, indicating a potential issue with the evaluation of the query.
  • Another participant speculates that the query might be misinterpreted as SELECT [FieldName] FROM Table WHERE [FieldName] = 0, suggesting that the %2 could be removed in the evaluation process.
  • One participant counters that this misinterpretation is unlikely since [FieldName] is a primary key, hinting at a possible bug in the server or client.
  • A later reply suggests testing the query without the %2 to see if it yields the same results.

Areas of Agreement / Disagreement

Participants express uncertainty about the cause of the issue, with no consensus on whether the problem lies in the query syntax, server behavior, or other factors. Multiple competing views remain regarding the interpretation of the query and its execution.

Contextual Notes

Participants mention potential conflicts with the % operator in different contexts, such as script parameters in Windows, and the implications of using SQL Zoo instead of a full SQL Server environment. There are unresolved questions about the behavior of the query and its results.

WWGD
Science Advisor
Homework Helper
Messages
7,802
Reaction score
13,106
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.
 
Technology 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.
 
Try typing in the query without the %2 and see if you get the same result set.
 

Similar threads

  • · Replies 51 ·
2
Replies
51
Views
6K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 18 ·
Replies
18
Views
4K
  • · Replies 7 ·
Replies
7
Views
5K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
11
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K