I have a situation where I want to set multiple variables when a condition mets.
IF(expr1, @reading:=0 and @prevdate:=@stepdate, @reading:=@reading)
as you see I want to set @reading:=0 and @prevdate:=@stepdate but this does not work.
how can I set multiple user-variables inside the true or false node?
Problem
The AND does short circuit evaluation.
The @reading:= 0 evaluates to 0, which is false.
0 and x is always 0, so MySQL does not bother to evaluate x.
OR suffers from the same problem: 1 OR x is alway true.
This is a way to speed things up by stopping as soon as the outcome if known.
Solution
Change it to @reading:= 0 XOR @prevdate:= @stepdate
This will solve your problem, because XOR does not suffer from short-circuit evaluation.
1 XOR x can be anything as well as 0 XOR x.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With