I have table “nol_voa” with different values and I am importing xml file with values in that table I want to insert in another table “#tmpRcIzm” the “id” values where the field “C_REF” has changed its value.
This is the code, what I wrote, but there is a mistake, it always adds two more “id” values which have not been changed.
insert into #tmpRcIzm
select distinct
a.id
from
openxml(@hDoc, '/art_komplekts/nol_voa') with #vc xd
join nol_art a on xd.art_cd = a.cd
left join #tmp t on t.cd = xd.art_cd
inner join nol_voa v on xd.id_art = v.id_art
where
xd.C_REF!=v.C_REF
You left join of #tmp, can introduce duplicates, and also the join on nol_art serve no purpose on this SQL. remove those two, and you should elminate your dups.