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
LVL 7
gudii9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
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
1
slightwv (䄆 Netminder) Commented:
>>syntax to use near 'Query all columns for a city in CITY with the ID 1661.

By chance, you do have a script you are running that has a line you want commented out that starts "'Query all columns"?

If so, a single quote isn't a comment in MySQL:
https://dev.mysql.com/doc/refman/5.7/en/comments.html

mysql> SELECT 1+1;     # This comment continues to the end of line
mysql> SELECT 1+1;     -- This comment continues to the end of line
mysql> SELECT 1 /* this is an in-line comment */ + 1;
mysql> SELECT 1+
/*
this is a
multiple-line comment
*/
1
kenfcampCommented:
Try

SELECT * FROM City WHERE ID = '1661';

Open in new window


Ken
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

NerdsOfTechTechnology ScientistCommented:
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
0
slightwv (䄆 Netminder) Commented:
Pretty sure my post and the link to the MySQL docs covered all that.  I'm not seeing where your post covered anything new.
0
NerdsOfTechTechnology ScientistCommented:
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.
0
slightwv (䄆 Netminder) Commented:
>>language that uses the ' comment syntax (like VBScript?) and to check for such a code leak into the SQL statement

Also posted in my post (there is a single quote after the double quote...).

By chance, you do have a script you are running that has a line you want commented out that starts "'Query all columns"?

If so, a single quote isn't a comment in MySQL:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NerdsOfTechTechnology ScientistCommented:
Ah, Sorry for the oversight.

OP please disregard my comments above
0
gudii9Author Commented:
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;
0
slightwv (䄆 Netminder) Commented:
>>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.
1
slightwv (䄆 Netminder) Commented:
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.
0
slightwv (䄆 Netminder) Commented:
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
1
NerdsOfTechTechnology ScientistCommented:
Vote updated.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.