vendredi 3 août 2018

IF statement in MySQL using @var

I have this code in MySQL

SELECT @v_new := IF( 
IFNULL(tpud_credit,0)+
IFNULL(tpud_value_cash,0) > 0, 1, 0) AS v_new
FROM trs_transaction_detail
WHERE tpud_pk = '1116801472ATR4019550';


IF (@v_new = 1) THEN SELECT @v_new; END IF;

When "SELECT @v_new" im placed after WHERE and not using IF, it can be to run. A problem why im got error when using that IF statement? something wrong?

Aucun commentaire:

Enregistrer un commentaire