gudii9
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
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try
Ken
SELECT * FROM City WHERE ID = '1661';
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
or you can use -- for a one-liner 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;
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';
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.
The rest is a working example of SQL comments (which @Netminder pointed out) put to work using OP's query.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ah, Sorry for the oversight.
OP please disregard my comments above
OP please disregard my comments above
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;
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.
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:
changing 1661 to '1661' doesn't fix anything.
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 Evaluationhttps://dev.mysql.com/doc/refman/5.7/en/type-conversion.html
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.
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:
In the original question the error message gave the database:
check the manual that corresponds to your MySQL server version
Vote updated.
And you have selected both SQL Server and MySQL, which platform are you using? And how are you executing this SQL?
»bp