I need to insert into TableA from TableB and avoiding duplicates, I tried the below it gives an error:
Violation of Primary Key constraint 'PK_TableA'. Cannot insert duplicate key ...
insert into TableA (DataField, TitleId, ClassId, ValueOrder, StrValue)
select 'Somtext',[title_id],'-1', '1',
[reference_text]
from TableB
where TableB.SomeColumn ='sometext 2014'
TableA
Title_id reference_text
1234 ABCD
1487 XFRE
1434 DERE
TableB
DataField TitleId ClassId ValueOrder StrValue
Now the Problem here is Data already exists in TableB. I need to avoid when TableA.Tile_id = TableB.TitleId, when this matches.
Title_ID, if so how is that decided?