批量插入,批量更新

--批量插入(事先查询相对应的字段到临时表#temp1)
SELECT ID,Name,Status 
INTO #temp1
FROM dbo.Doctor d
WHERE d.ID NOT IN (SELECT ID FROM dbo.UP_Doctor)


INSERT INTO dbo.UP_Doctor
( ID, Name, Status )
SELECT * FROM #temp1

DROP TABLE #temp1;


--批量更新(事先查询相对应的字段到临时表#temp2)
SELECT ID,Name,Status 
INTO #temp2
FROM dbo.Doctor

UPDATE dbo.UP_Doctor
SET Name=#temp2.Name,
Status = #temp2.Status
FROM #temp2
WHERE dbo.UP_Doctor.ID = #temp2.ID

DROP TABLE #temp2;

 

posted @ 2019-01-10 13:58  蜗牛的礼物  阅读(161)  评论(0编辑  收藏  举报