I have written this SQLite statement and I am getting syntax error on the following line:
update List SET number = (CASE WHEN number>=3 then number++ WHEN number=1 then 3 ELSE number END) WHERE listKey=3;
The error is:
SQL error: near "WHEN": syntax error
I tried various versions, adding braces at places and all, but can't figure out the error. Can anyone please help me with this?
If SQLite uses "++" syntax, I've never seen it. Try then number + 1 instead.
Related
Sample
I tried to run a query with 2 IF keyword. I ma getting a syntex error in the second IF clause. How can I keep the second IF different from the first one.
Next time please give your statement as text, not a screenshot.
You need a comma separating temperature and windspeed. After correcting that, next error will be in wdsp, do you want it as provided or cast to float64?
Question, if someone mistyped a comparison in the AND part of a WHERE clause, so that they ended up comparing a value against itself, would that throw an error, or would it simply fail silently? I ask because I came across a WHERE clause that includes the following line:
WHERE ...
AND (note_details.id_number = note_details.id_number)
How would this be handled?
It would work. There is no error.
The logic:
where x = x
is equivalent to:
where x is not null
I want to get data from database but the format of values that are compared do not tally.
The numbers in database are saved in weird format - sometimes are rounded and some of those are decimals (10, 14, 15, 12.44, 16.10, etc.)
In array I have values rounded on 2 decimals though.
I want to get data from database like so:
$foundPayments = $this>paymentsRepo>newQuery()>whereRaw("CONVERT(DECIMAL(10,2),payments.amount) = :payments", ['payments' => $payments]);
Althought, I end up with an error like this: Syntax error: 7 ERROR: syntax error at or near ","
I am not sure if the code works in laravel 5.1 with sending params like I do but thats not really what I do care for in that - the same error apperars even when I do not use variable.
EDIT:
I am using Postgres.
I think that the syntax that you are using for the convert function is wrong. You should first pass the value then the type to which you are converting to.
But please try the cast function, I think that it should give you the expected result.
$foundPayments = $this->paymentsRepo->newQuery()
->whereRaw("CAST(payments.amount as DECIMAL(10,2)) = :payments",
['payments' => $payments]);
I'm trying to run the following query on a database to replace the leading characters of certain rows.
UPDATE table SET path = :newpath || SUBSTRING(path FROM :pathlen)
WHERE path STARTING WITH :oldpath
So for parameter :newpath = foo, :oldpath = bar and :pathlen = 4, I want this
bar\wibble
to be changed to ...
foo\wibble
However, I get the error "expression evaluation not supported" and I'm not sure why. Replacing :pathlen with a literal 4 works correctly, so it's definitely the SUBSTRING causing the problem.
In my Rails application I need to check if an object exists and if it does, I need to assign the latitude and longitude attributes of that object to two external variables named latitude and longitude.
my controller code
def query
if ( Coordinates.where(city :params[:show]).exists?) equal? 1) then
a=Coordinates.where(city: params[:show])
latitude=a.latitude
longitude=a.longitude
end
But When I run the program In the browser I am getting syntax error despite I tried several times changing the syntax The error I am getting is "syntax error, unexpected tFID, expecting keyword_then or ';' or '\n'". Anybody please help me how to solve this problem ,thanks in advance
I've got several remarks:
in Ruby the syntax for an if is generally (without then)
if condition
code
end
where returns a ActiveRecord Association, thus it is a collection so you can't call a.latitude for example. Try Coordinates.where(city: params[:show]).first or something like that.
have you defined a method called equal?? If not there is at least a . missing.
The if statement is more or less useless.
def query
a = Coordinates.where(city: params[:show])
b = a.first
if a.count == 1
latitude = b.latitude
longitude= b.longitude
else
# do something else
end
end
This line seems to be the problem:
( Coordinates.where(city :params[:show]).exists?) equal? 1)
What exactly do you want to know? In this case it might be better to explain it to us in words, because your code seems confusing. Ayonix has a working example of the query method, but I'm not sure if that method describes exactly what you want to know.