Is something wrong with my SQL Query? [closed] - sql

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
SELECT * FROM iveflownthat.messages WHERE from=1 OR to=1
Its keeps giving me errors. I checked to make sure that the fields, table, and database name are correct.

FROM and TO are keywords. You should use them like this: [FROM], [TO]
SELECT * FROM iveflownthat.messages WHERE [from]=1 OR [to]=1

"from" is a keyword in SQL. ENclose it in square brackets... " WHERE [from] = 1 OR [to] = 1 "
edit" What Alireza said...

You named your column 'from' which is a reserved word, so you're getting this error due to bad syntax.

Related

Comparison with '{0}' in SQL SELECT [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 months ago.
Improve this question
I have to take over old colleague's code and trying to understand this one SQL statement like below:
SELECT * FROM my_table WHERE date_key = '{0}'
Column date_keycontains int values such as 20220712, 20220120, etc.
The first guess is that SELECT statement filters for rows with 0 value in column date_key. However, when running that line of code, I receive this error :
SQL Error [100038] [22018]: Numeric value '{0}' is not recognized
What exactly does that line of code do?
That looks like a placeholder, replaced with an actual value in code when calling the query.
See similar What is {0},{1},{2},{3} in the SQL query

How to find value that have some charcter in third position? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I Couldn't find the value that has 'r' in the third position using LIKE operation in SQL.
could anyone help me, please?
I think it would be better to write something like this.
SELECT <column>, FROM <table> WHERE <condition> LIKE "__r%";
EDIT:
This is tested and functional for SQL Server and Oracle DBMSs.
SELECT * FROM <table> WHERE substring(<column>,3,1) = 'r'
Try this. This is using SQL Server which will yield the result you are looking for.
You want to get the r from 'scr' with position 3
Try this
SELECT * FROM Customers
WHERE CustomerName LIKE '__r%';
position is count of _.

Syntax error near the keyword order [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
When I perform this query
SELECT
orders.id, orders.order - time, orders.pizza.id,
orders.pizza.type, orders.pizza-size, orders.quantity,
FROM
orders
INNER JOIN
permit ON orders.id = pizza.id
WHERE
([username] = #username)
I get an error
Syntax error near the keyword order
Any ideas how to solve this?
Since you have no order by clause and the error message is complaining about your statement near the order keyword, I surmise that there are two possibilities.
The first is that you've left the s of one of your table specifiers, using order instead of orders, despite your transcription.
The second is that orders.order-time is incorrect, being treated as orders.order - time. In fact, I'd be a little worried by many of your names, including those that have two periods (.) in them. You may want to check if the - and the subsequent . characters should be underscores (_) instead.
You also have a trailing comma after the last column selection (before the from), which is not valid SQL.
Assuming SQL-Server
SELECT orders.id, orders.[order-time], orders.[pizza.id], orders.[pizza.type], orders.[pizza-size], orders.quantity,
FROM orders INNER JOIN permit ON orders.id = pizza.id
WHERE ([username] = #username)
Remove the comma after the final column before FROM.
Also could you explain what the "> on the end is for, was this pasted in error?

SQL LIKE doesn't find obvious matches [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm writing the following SQL query:
SELECT *
FROM OS
WHERE OS.VERSION LIKE '%1%';
In my table there are rows with char 1 in it. However, it returns an empty result.
I changed a little bit the LIKE clause to different values, but it still doesn't work.
What can I do to fix that?
Try double-quotes and * for wildcards. You are using Oracle syntax instead of Access syntax.
LIKE operation can't be used with columns of integer type. I assume that OS.Version is of integer type?
Edit1:
If you are referring to MS Access then you have to do the LIKE with stars (*) instead of %.

Overcoming the reserved word "IN" in sql server [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Just for reference I am using SQL Azure.
I noticed when I am trying to select data from a table based on a license plate and the state of that plate I get no results back if the state is "IN". I realize the word "IN" is reserved in SQL server; however, I am containing that within quotes in my query. I currently am in testing phase and have only one record in the table which has a lisence plate 287YGB and state IN.
If I write my query as follows I get nothing back.
SELECT MakeModel, CitizenID, VehicleID FROM tblVehicles WHERE tblVehicles.Lisence = '287YGB' AND tblVehicles.PlateState = 'IN'
If I write my query this way I get back my result. But this is not good enough.
SELECT MakeModel, CitizenID, VehicleID FROM tblVehicles WHERE tblVehicles.Lisence = '287YGB'
And finally, if I write my query this way I get the only row in the table.
SELECT MakeModel, CitizenID, VehicleID FROM tblVehicles
From these tests I can see that the last where parameter is causing the problem. I am assuming it is due to the fact that the word "IN" is reserved. Is there a way around this?
Reserved words usually only cause problems if you're using them as field names, and in that case you need to wrap them with brackets ("[]") to eliminate the problem. I will amost guarantee you that your PlateState has some garbage in it, so you need to either trim it first (LTRIM(RTRIM(PlateState)) = 'IN') or use Like '%IN%' instead, and this will return the results you expect.
try this
SELECT MakeModel, CitizenID, VehicleID FROM tblVehicles WHERE tblVehicles.Lisence = '287YGB' AND LTRIM(RTRIM(tblVehicles.PlateState)) = 'IN'