it's a key violation error, just like it says. You might be appending records that would create a duplicate number in a PK field, or something similar. check your PK index setting and the records you're appending.
This query executes when a dropdown is changed. I did try this query seperately in the query biuilder it works perfectly. but the same doesnt run when the dropdown changes.