Validate Duplicates While Performing a Bulk Insert
Posted on 2007-08-09
I have a flat table that i use to stage CSV Lead Imports in. It has four fields: home,work ,cell,alt phone. Home will always have a number in it. Cell, Work and Alt could be 0. I'd like to be able to bulk insert this data, but not insert rows from this table where ANY of these four fields matches to a phone number i have in my PhoneNumber table AND don't match to any other record in my staging table.
For instance, if Lead A has a home of 5555555555 and B has a Cell of 5555555555, then only A would go in, etc, etc, etc.
I really don't want to use a cursor, but I'm thinking that the code I would need to write to only select a distinct lead (based on those numbers and considering some could be 0 for many rows) from this table could get ugly. If i cursor, then lead A will be in the phone number table by the time I get to lead B. HOWEVER, I was wondering if these is any way to validate as i'm doing the bulk insert. Probably Not. I'm taking suggestions.