對(duì)記錄進(jìn)行增刪改的sql語(yǔ)句
--不存在的記錄刪掉
delete a from ECOrganizationPositionRelation a left join @ECOrganizationPositionRelation b
on a.OrganPostionID=b.OrganizationID and a.PositionID=b.PositionID
where not exists(select * from ECOrganizationPositionRelation where rganizationID=b.OrganizationID and PositionID=b.PositionID)
--存在的記錄修改
update a set
rganizationID=b.OrganizationID,
PositionID=b.PositionID
from ECOrganizationPositionRelation a,@ECOrganizationPositionRelation b
where a.OrganizationID=b.OrganizationID and a.PositionID=b.PositionID
--沒(méi)有的記錄增加
insert into dbo.ECOrganizationPositionRelation(OrganPostionID,OrganizationID,PositionID)
select
NEWID(),
OrganizationID,
PositionID
from @ECOrganizationPositionRelation b
where not exists(
select * from ECOrganizationPositionRelation
where rganizationID=b.OrganizationID and PositionID=b.PositionID
)
作者 萬(wàn)德源