[SOLVED] Help for SQL procedure lazarus / 16-Databases ---------------------------------------------------------------------- egsuh · 2019-07-22 07:40 Hi, I know this is not the right place to ask this, but I do not know better place. What I'm trying to do is conditional operation within FireBird stored procedure. Specifically, Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i insert into tableA   (f1) values (:value1);// if successful:    select f2 from tableB where where tableA.pkfield = tableB.pkfield into :value2;    update tableA set f2=:value2;    update tableB set f3=:value1 where tableA.pkfield = tableB.pkfield;  The reason to check success is that f1 is field of unique values. Well, I might not have to check the success or not because there there are some SQL error then the followings will not executed. ---------------------------------------------------------------------- GAN · 2019-07-22 19:47 select f2 from tableB where where tableA.pkfield = ---------------------------------------------------------------------- valdir.marcos · 2019-07-23 02:28 Quote from: egsuh on July 22, 2019, 09:40:50 amHi, I know this is not the right place to ask this, but I do not know better place. What I'm trying to do is conditional operation within FireBird stored procedure. Specifically, Code: SQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i INSERT INTO tableA   (f1) VALUES (:value1);// IF successful:    SELECT f2 FROM tableB WHERE WHERE tableA.pkfield = tableB.pkfield INTO :value2;    UPDATE tableA SET f2=:value2;    UPDATE tableB SET f3=:value1 WHERE tableA.pkfield = tableB.pkfield;  The reason to check success is that f1 is field of unique values. Well, I might not have to check the success or not because there there are some SQL error then the followings will not executed.You should control the transaction (commit/rollback) on Lazarus, not on Firebird, which would mean to do everything or nothing. Then, try something as simple as this on Firebird: Code: SQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i EXECUTE Block ASBEGIN  IF (NOT EXISTS((SELECT F1 FROM TableA WHERE F1 = :value1))) THEN   BEGIN     INSERT INTO tableA(f1) VALUES (:value1);  UPDATE tableA SET f2 = (SELECT f2 FROM tableB WHERE WHERE tableA.pkfield = tableB.pkfield);    UPDATE tableB SET f3 = :value1 WHERE tableB.pkfield = tableA.pkfield;   ENDEND https://firebirdsql.org/file/documentation/reference_manuals/fblangref 25-en/html/fblangref25-dml-execblock.html ---------------------------------------------------------------------- egsuh · 2019-07-23 02:37 @marcos Yes, thank you very much. This is exactly what I wanted.