I am trying to run a replace into DB call, but I only want it to execute if the supplied printerid# is greater then the database stored printerid#.
Here is my example code which hopefully makes sense of this
unitid = 2382;
printerid = 9826;
REPLACE INTO devices (unitid, printerid)
VALUES ('"+ unitid +"', '"+ printerid +"')
WHILE '"+printerid+"' > devices.printerid
So for example, if the devices database already has an entry for unitid 2382 that has a printer ID of 9999, then the SQL call should do nothing, but if it had a printer ID of 8888 it would replace it with my new printer ID of 9826.
The above listed SQL code doesn’t work though obviously. 🙁
Thanks!
You could also use
INSERT INTO ... ON DUPLICATE KEYassuming you have a primary/unique key onunitid: