Okay I have 2 tables:
Table A - holds a list of new hardware serial numbers and their corresponding model (no constraints or indexes)
Table B - holds a distinct list of current serial numbers and the corresponding model numbers (primary key on serial_numbers)
Since Table A has no constraints duplicates may exist.
Additionally, table A is actually an Excel spreadsheet that is maintained by an employee that records new hardware as they come in. I am pulling the data from Table A to insert into Table B and so construct the insert query to prohibit any entries into Table B (which has a primary key set on the serial_number column) so duplicate entries aren't attempted on the insert.
insert into system_serial_numbers(serial_num,system_model)
select [sys #], [model #] from EXCEL...Master$
where [sys #] not in (select serial_num from system_serial_numbers)
and [model #] is not null
When I run this query I receive the following error and the insert fails
Violation of PRIMARY KEY constraint 'pk_serial'. Cannot insert duplicate key in object 'dbo.system_serial_numbers'.
The statement has been terminated.
If I take one of the records retrieved from the select statement and insert it into the table it succeeds which leads me to believe that maybe one of the records returned is a duplicate but theoretically this shouldn't be happening because I specified that only records not in the existing destination table be inserted.
Anyone have any ideas why this problem is happening or have ever seen this before???