Hi,I have two tables:declare @a table (id int, dt datetime, nme varchar(10))insert @aselect 1, '10/08/2006', 'nme 1c' union allselect 2, '02/03/2006', 'nme 2a' union allselect 3, '05/30/2001', 'nme 3a' union allselect 4, '01/06/1997', 'nme 4a'declare @b table (id int, dt datetime, nme varchar(10))insert @bselect 1, '01/12/1989', 'nme 1a' union allselect 1, '12/09/1992', 'nme 1b' union allselect 1, '06/07/2001', 'nme 1c' union allselect 2, '02/03/2006', 'nme 2a'
Table a has id as PK, table b both id and dt. Table b is in effect a history table for table a. I want to insert records from a to b, but only these that aren't there already. I was thinking about using "where id, dt not in (...)" to exclude records already in b, but IN only works for one column. How else can I achieve this?To be clear, here's what I want in b:id dt nme--------------------------------1 '01/12/1989' 'nme 1a' -- old1 '12/09/1992' 'nme 1b' -- old1 '06/07/2001' 'nme 1c' -- old1 '10/08/2006' 'nme 1c' -- new from a2 '02/03/2006' 'nme 2a' -- old (one from a not inserted)3 '05/30/2001' 'nme 3a' -- new from a4 '01/06/1997' 'nme 4a' -- new from a
Thanks in advance for any suggestions