I have a unique index set up in tblCombined. It is set up on the fields called cyDate, dtlNr, and seq, in that order.
I have another table – a staging table – called tblDailyResults. It has the exact same fields as tblCombined, but no index. Each day, I receive records into this staging table from a feed.
What I’d like to do is setup a “catch” if you will, so that if a duplicate record that violates the unique index, it won’t error out – rather, it will just not be inserted; it will remain in the staging table (I can then send out an alert noting such and manage it from there).
This is what I’ve tried:
Insert Into tblCombined
(
cyDate
,dtlNr
,seq
,chCode
,opCode
,nrCode
)
Select
cyDate
,dtlNr
,seq
,chCode
,opCode
,nrCode
From tblDailyResults
Where Not Exists (Select cyDate ,dtlNr ,seq From tblCombined)
But, this doesn’t seem to be working. I tested out a couple of records – changing the fields from what was already inserted, and it still excludes the non-duplicate records. I admit I’m new to using “not exists” so perhaps I’m not using it correctly.
I also tried Where Not In, but that doesn’t seem to work for multiple columns.
Any suggestions is appreciated. Thanks!
you need a
wherein thenot existspart too, like …