Hi,
I have an SQL insert statement that runs fine and the desired records are inserted. But sometimes, maybe one of the records it's trying to insert already exists and therefore produces a duplicate record error. I would like it to handle this error so that the statement doesn't fail and at least the rest of the records are inserted, just skipping the duplicate. How can I monitor for sqlstt = '23505' as part of my statement so that it inserts all the records it can and just skips those that are duplicates?
For example, how would I integrate that error handling into this simple example statement:
Insert into MYFILE(KEY1, FIELD2, MYTS1, MYTS2)
select ACCT, STRNO, '0001-01-01', '0001-01-01'
from MYFROMFILE
where STS = 'A'
and SYR = 22 and SMO >= 4 and SDT >= 1
I will run this kind of statement interactively sometimes but will also be putting it into an SQLRPGLE program with variables for the criteria, such as the year, month, and day.
TIA!
I have an SQL insert statement that runs fine and the desired records are inserted. But sometimes, maybe one of the records it's trying to insert already exists and therefore produces a duplicate record error. I would like it to handle this error so that the statement doesn't fail and at least the rest of the records are inserted, just skipping the duplicate. How can I monitor for sqlstt = '23505' as part of my statement so that it inserts all the records it can and just skips those that are duplicates?
For example, how would I integrate that error handling into this simple example statement:
Insert into MYFILE(KEY1, FIELD2, MYTS1, MYTS2)
select ACCT, STRNO, '0001-01-01', '0001-01-01'
from MYFROMFILE
where STS = 'A'
and SYR = 22 and SMO >= 4 and SDT >= 1
I will run this kind of statement interactively sometimes but will also be putting it into an SQLRPGLE program with variables for the criteria, such as the year, month, and day.
TIA!
Comment