I have a table, called “report”, which contains report IDs and their respective extension codes. Currently, as an example, the only extension for each ID is ‘TXT’. I am trying to insert a new extension (‘RTF’) into each existing report ID. Here is my code:
merge into report a
using (select x.rpt_id as value1, 'RTF' as value2
from report x
where x.extension <> 'RTF') b
on (a.rpt_id = b.value1)
when not matched then
insert values (b.value1, b.value2);
I get no errors, but nothing gets inserted…
It would be helpful to post a sample of the data before you run your statement (just a sample, of course) and the desired data after you’ve run your statement.
It sounds like you are looking for something like
If the primary key is actually a composite constraint on the combination of
rpt_idandextension, and your goal is to take your table of N reports each with an extension ofTXTand create N new rows with the samerpt_idand an extension of `RTF’, this will work.Based on the error you are getting, it certainly appears that the primary key is not defined on the combination of
rpt_idandextension.