LoadCustomTableUsingExcel function not working when loading to table having unique constraints
Hi,
I am using the LoadCustomTableUsingExcel function to load an Excel file to an application table. The function seems to be working fine in most cases. However, I am having issue with tables having unique constraints.
The table has Payroll, PeopleGroup and Amount columns. The unique constraint was added because users can also insert into the table using an SQL editor component, so we want to avoid them do be able to insert duplicated rows.
When trying to load a row which already exist in the table using the LoadCustomTableUsingExcel function I get the following error (example): “Column ‘Payroll, PeopleGroup' is constrained to be unique. Value 'Payroll_AE, PplGroup001' is already present.”
This issue only appears when loading in Merge. Replace works fine. Normally (with table not having a unique constraint) it is not an issue loading rows that are already in the application table because the Merge tag in the Excel file make so that only new rows are added to the table while rows already present are ignore and not duplicated (as you would expect from a merge).
Thank you for any suggestion you can give me
Hi Andrea,
I don't know much about this function as I haven't used it (here are some other .net native functions to load Excel files that I have used)
Regardless, I think the simplest option might be to load your data to a staging table and then insert/update/merge the rows from there to your main table. The MERGE sql statement sounds like it would be your friend here. This would allow you to maintain your constraints and not have to change your existing process significantly (just a different target table for the LoadCustomTableUsingExcel and an SQL statement execution.
- Daniel