我有一个要求,我需要为特定 EmpID 插入具有不同哈希值的记录。以下是暂存记录和主记录中的一些示例值。Staging 每周获取值,需要根据 ID 和 hashvalue 将值插入到 master 中,当所有记录都被处理时,表被截断。
Week 1 in staging: EMpd ID Hash Value
1000 1; 2000 2
2 records gets inserted in master
Week2 in staging: EMPID hashvalues
1000 -3
2000 2
3000 5
Master should have 1000 1;1000 -3; 2000 2; 3000 5
Week 3 in staging: EMPID hashvalues
1000 -5
2000 -9
3000 5
Master should have 1000 1;1000 -3; 1000 -5;2000 2; 2000 -9;3000 5
I have tried doing
insert into EMP_MASTER (EMPID,EMPNAME,hashValue)
select mas.*,stg.hashvalue FROM [EMP_master] mas (nolock)
INNER JOIN [EMP_staging] stg (nolock) ON mas.EMPID = stg.EMPID
WHERE mas.hashvalue != stg.hashvalue and not exists
(select 1 from [EMP_Master](nolock)
where EMPID=stg.EMPID and hashValue=stg.hashvalue ) order by EMPID;
这给出了 1000 的重复值。有人可以帮我吗?谢谢先生