Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

query not working

Below query not working


SELECT * FROM City WHERE ID=1661;

i see error as
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Query all columns for a city in CITY with the ID 1661.


SELECT * FROM City WHER' at line 1

please advise
Avatar of Bill Prew
Bill Prew

Where is this text in what you are executing, I didn't see it.  Can you post exactly what you are doing?

And you have selected both SQL Server and MySQL, which platform are you using?  And how are you executing this SQL?


»bp
SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try

SELECT * FROM City WHERE ID = '1661';

Open in new window


Ken
It looks as if some sort of Microsoft ' quote comment got into your query. Check your code for an improper enclosure that leaked out the comment.

Or if you meant for a comment to be in your SQL query, Use proper SQL commenting.

In the case of a SQL comment, I personally use /* */ because it is whitespace and multi-line safe
/* Query all columns 
for a city in CITY 
with the ID 1661 */ 
 SELECT * 
 FROM City 
 WHERE ID=1661;

Open in new window


or you can use -- for a one-liner comment
-- Query all columns for a city in CITY with the ID 1661
 SELECT * FROM City WHERE ID = '1661';

Open in new window

ref: https://www.w3schools.com/sql/sql_comments.asp
Pretty sure my post and the link to the MySQL docs covered all that.  I'm not seeing where your post covered anything new.
My contribution would be the possibility of the OP using some MS-type language that uses the ' comment syntax (like VBScript?) and to check for such a code leak into the SQL statement.

The rest is a working example of SQL comments (which @Netminder pointed out) put to work using OP's query.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ah, Sorry for the oversight.

OP please disregard my comments above
Avatar of gudii9

ASKER

SELECT * FROM CITY WHERE ID='1661';
above worked
below did not
SELECT * FROM City WHERE ID=1661;

i am trying on ms sql server

i thought sql syntax same across all databses like sql server, sybase, db2 etc?
is it is different?


also below worked fine

/* Query all columns
for a city in CITY
with the ID 1661 */
 SELECT *
 FROM City
 WHERE ID=1661;
>>i thought sql syntax same across all databses like sql server, sybase, db2 etc?

Basic SQL only.  Every vendor has little add-ons to the ANSI SQL.
Sorry but I disagree that #a42460016 is a possible solution.

The provided error message gives you text not in the SQL.  That is the first indication of the problem.

Then you have:
12.2 Type Conversion in Expression Evaluation
When an operator is used with operands of different types, type conversion occurs to make the operands compatible. Some conversions occur implicitly. For example, MySQL automatically converts numbers to strings as necessary, and vice versa.
https://dev.mysql.com/doc/refman/5.7/en/type-conversion.html

changing 1661 to '1661' doesn't fix anything.
Hate to object again and it is splitting hairs but:  Asking to clarify database product wasn't necessary.

In the original question the error message gave the database:
check the manual that corresponds to your MySQL server version
Vote updated.