I have a table ([ArtTblHist]) in which changes to my item attributes are being logged.I need to find a way to only insert into this table from my source table when any of the item attributes have changed from the previous entry in table [ArtTblHist]:--Create tablesCREATE TABLE ArtTblHist(Article VARCHAR(8),ArtCategory CHAR(3),ArtStatus INT,ArtRank INT,DateFormatted char(10))CREATE TABLE ArtTbl(Article VARCHAR(8),ArtCategory CHAR(3),ArtStatus INT,ArtRank INT,DateFormatted char(10))--Insert records in source table ArtTblINSERT INTO ArtTbl VALUES('1103001','BAR',1,4,'2011-04-22')INSERT INTO ArtTbl VALUES('1103002','QTR',1,12,'2011-04-22')INSERT INTO ArtTbl VALUES('1103003','QTR',4,19,'2011-04-02') --Insert records in history table ArtTblHistINSERT INTO ArtTblHist VALUES('1103001','BAR',1,10,'2011-03-28')INSERT INTO ArtTblHist VALUES('1103001','BAR',1,10,'2011-03-30')INSERT INTO ArtTblHist VALUES('1103002','QTR',1,12,'2011-03-28')INSERT INTO ArtTblHist VALUES('1103002','CDW',2,12,'2011-03-29')INSERT INTO ArtTblHist VALUES('1103003','QTR',1,3,'2011-03-28')INSERT INTO ArtTblHist VALUES('1103003','QTR',3,3,'2011-03-29')INSERT INTO ArtTblHist VALUES('1103003','QTR',1,3,'2011-03-30')INSERT INTO ArtTblHist VALUES('1103003','QTR',4,19,'2011-04-02')Now I would need to insert the records for articles 1103001 and 1103002 from ArtTabl into ArtTblHist but not 1103003 because the record is identical to the last record for that article in the history table.I could retrieve the respective last entry for each article from the history table like this: SELECT * FROM (SELECT Article,ArtCategory,ArtStatus,ArtRank,DateFormatted, Row_number() OVER (Partition by Article Order by DateFormatted DESC) as [SQN] FROM ArtTblHist) listWHERE SQN = 1
How can I join this result set to my ArtTbl to determine which rows to inert?Any help is appreciated.