IF (EXISTS
(SELECT documentsRepo.DocumentRouteNumber
FROM documentsRepo
INNER JOIN dreDocuments ON documentsRepo.DocumentRouteNumber = dreDocuments.DocumentRouteNumber))
UPDATE DocumentsRepo
SET documentsRepo.documentTypeID = dreDocuments.DocumentTypeID,
documentsRepo.DepartmentID = dreDocuments.DepartmentID
FROM documentsRepo
INNER JOIN dreDocuments ON documentsRepo.DocumentRouteNumber = dreDocuments.DocumentRouteNumber ELSE
INSERT INTO documentsRepo (DocumentTypeID, DepartmentID, DocumentRouteNumber, SOURCE, Destination)
SELECT DocumentTypeID,
DepartmentID,
DocumentRouteNumber,
SOURCE,
Destination
FROM dreDocuments
我正在使用上面的代码来更新或插入记录。它在第一条记录插入中正常工作。更新完美。但是下一个插入批次不起作用。