Ive been experimenting with inserting data and updating if there is a dup. Here is my code. All of these fields are keys. Each is unique and if there is a dup, all three fields are consistent. Only one NUMBE for one TYPE for one TrackingNumber and so on.
string statement =
"INSERT INTO SOP10107 VALUES(@SOPNUMBE, @SOPTYPE, @Tracking_Number)
ON DUPLICATE KEY
UPDATE(@SOPNUMBE = SOPNUMBE + 1,
@SOTYPE = SOTYPE + 1,
@Tracking_Number = Tracking_Number + 1 )";
Since I am new, Im not sure if this is correct (or anywhere near correct), I think the basic format is right, but the specific grammer and wording I am having some trouble on. The error will come back and say that there is a problem with “ON”. It is most likely a format error. Anyone care to help me out or shed some light on the matter? Thank you so much in advance!
You can use the new MERGE statement in SQL 2008
MERGE Command in SQL