The Powerful SQL Upsert
January 27, 2015 Ted Holt
As you well know, a common task in business computing is to update an entity (customer, vendor, purchase order line, etc.) that exists, but add the entity if it doesn’t exist. In RPG this requires two operations–an update and a write–within a conditional statement. In SQL one statement handles the whole shebang. Here’s how it works. Here’s some RPG III code that illustrates the situation. FCUSTF UF E K DISK . . . code omitted C CUSKEY KLIST C KFLD COMP C KFLD ACCT C* . . . more code omitted C* HILOEQ C CUSKEY CHAINCUSTREC 99 C* . . |