insert and update query with same click event lazarus / 16-Databases ---------------------------------------------------------------------- fiazhnd · 2017-08-10 14:57 I want to insert and update the record (With SQL Query) with the same click event on BtnSave. i am using access ---------------------------------------------------------------------- mangakissa · 2017-08-11 06:26 Do you mean the same table insert/update ---------------------------------------------------------------------- fiazhnd · 2017-08-12 11:05 Yes, i want to create a query which checks the database table if ID(PK) exit it updates otherwise it creates a new record. ---------------------------------------------------------------------- JD · 2017-08-12 11:33 Quote from: fiazhnd on August 12, 2017, 01:05:51 pmYes, i want to create a query which checks the database table if ID(PK) exit it updates otherwise it creates a new record. Like a PostgreSQL UPSERT command? Don't know if MS Access supports that but it can be creatively done with an IF statement. ---------------------------------------------------------------------- fiazhnd · 2017-08-12 14:53 I am using Delphi currently for project anyway if anyone can give me an example will great help. ---------------------------------------------------------------------- shobits1 · 2017-08-12 17:26 you need to do it into 2 separate queries like this: first call the insert query to, add new record if none found. Code: MySQL  [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 Table1 ( ID, Col1, Col2, .... )SELECT TOP 1 ID_VAL, COL1_VAL, COL2_VAL, ....FROM Table1WHERE ID_VAL NOT IN (SELECT ID FROM Table1 WHERE ID = ID_VAL);  then call the update query to update the record if exist Code: MySQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i UPDATE Table1 SET ID = ID_NEW, Col1 = Col1_NEW, Col2 = Col2_NEW, ....WHERE ID = ID_VAL;  I don't know if this is the best way but it works. ---------------------------------------------------------------------- ASerge · 2017-08-12 17:51 See also https://stackoverflow.com/questions/6199417/upserting-in-ms- access/37014004#37014004 or https://www.experts- exchange.com/questions/28713136/Can-I-use-the-SQL-MERGE-statement-in- a-query-in-Access-2010.html