dimanche 26 juin 2016

Check Before Inserting

I need to check a value before inserting. However for some reason I can't figure it out. Here's my code:

set @accID = (select id from table2); 

IF @accID IS NOT NULL THEN
    INSERT INTO task
    (account_id)
    VALUES (@accID);
END IF;

What is wrong with the code above as it shows invalid sql syntax error?

Aucun commentaire:

Enregistrer un commentaire