How to set multiple user variables inside IF on MySQL

I have a situation where I want to set several variables when the condition is mets.

IF(expr1, @reading:=0 and @prevdate:=@stepdate, @reading:=@reading)

as you can see, I want to install @reading:=0 and @prevdate:=@stepdate, but that will not work.

how to set multiple user variables inside trueor falsenode?

+3
source share
1 answer

The problem
AND is evaluating a short circuit.
The value @reading:= 0is 0, which is incorrect.

0 and xalways 0, so MySQL does not evaluate x.
ORsuffers from the same problem: 1 OR xalways right.
This is a way to speed up the process by stopping as soon as the result is known.


@reading:= 0 XOR @prevdate:= @stepdate

, XOR .

1 XOR x , 0 XOR x.

+2

All Articles