我想将临时表中的数据插入到原始表中
结构相同,但有 3 个这样的键
table original
{NIP_SPV nvarchar (10),
NIP_SUB nvarchar (10),
TransActionDate date,
...
}
我想在数据不存在的地方插入数据
我的代码看起来像这样
IF NOT EXISTS (
SELECT * FROM table_original a Inner Join table_temp b
on a.transactiondate = b.transactiondate and a.nip_spv = b.nip_spv
and a.nip_sub = b.nip_sub )
Begin
INSERT INTO T_EmployeeGroup
select nip_spv,nip_sub,spv_usertype,sub_usertype,appr_year
from table_temp
END
Else
Begin
Update A
A.column_n =B.column_n
from table_original A
Inner JOIN table_temp B
on a.transactiondate = b.transactiondate and a.nip_spv = b.nip_spv
and a.nip_sub = b.nip_sub
end
案例是
when i insert data for the second time is failed
first case i insert 10 data
second case i insert 20 data(10 old data from first case)
我未能从新数据中插入 10 个数据。
我错过了什么?