0

I am using a MySQL transaction. If the initial where myHistoryNum result (match name+rowActive) is not NULL, then continue the transaction.

I have tried various combinations, however cannot get the insert statement to trigger when myHistoryNum is set.

history | uuid | name  | rowActive
24      | abcd | Art   | 1          <<< is match, trigger an insert
999     | zxcv | Art   | 0          <<< no match, do not trigger insert


start transaction; 
select @myHistNum := max(history), @olduuid := uuid 
from mytable WHERE (name=art AND rowActive=1);

# START IS NOT NULL test
CASE WHEN @myHistNum IS NOT NULL THEN
set @histNum = @histNum  + 1;
INSERT INTO mytable 
.....
END;                                      <<<ALT, tried END AS;
commit;

also tried

IF @myHistNum IS NOT NULL
 THEN 
   .....
END IF;
commit;
art vanderlay
  • 2,341
  • 4
  • 35
  • 64
  • Possible duplicate of [MySQL Conditional Insert](https://stackoverflow.com/questions/913841/mysql-conditional-insert) – Nick Dec 03 '18 at 22:26

1 Answers1

0

If I'm not mistaken, control flow statements (like IF, WHEN) can only be used within stored programs in MySQL

fifonik
  • 1,556
  • 1
  • 10
  • 18