--  PACS 报告和已选图片的ReportNo同步
-- 
-- SELECT *  FROM	pacs.DICOMSERVER.dbo.PEIS_PacsResult WHERE PatientCode=  '71013'
-- SELECT *  FROM	PACS.DICOMSERVER.DBO.ImgForReport WHERE AccessionNumber= '1284796'
-- 
-- SELECT * FROM Enrollment_FeeItem WHERE EID=71013 AND ItemClass='检查' 563602/615130
-- SELECT * FROM report WHERE EID=71013  563602/615130
-- 报告
-- UPDATE Report SET ReportNo=T.ReportNo FROM (
-- SELECT DISTINCT A.ID AS ReportNo,A.EID,B.ID FROM Enrollment_FeeItem A
-- LEFT JOIN report B ON A.EID=B.EID AND A.OldId=B.ReportNo
-- WHERE A.OldId IS NOT NULL AND B.ReportNo IS NOT NULL AND A.ID<>B.ReportNo
-- ) T WHERE Report.EID=T.EID AND Report.ID=T.ID

-- 图片
-- UPDATE Exam_PacsImage SET ReportNo=T.ReportNo FROM (
-- SELECT DISTINCT A.ID AS ReportNo,A.EID,B.ID   FROM Enrollment_FeeItem A
-- LEFT JOIN Exam_PacsImage B ON A.EID=B.EID AND A.OldId=B.ReportNo
-- WHERE A.OldId IS NOT NULL AND B.ReportNo IS NOT NULL AND A.ID<>B.ReportNo
-- ) T WHERE Exam_PacsImage.EID=T.EID AND Exam_PacsImage.ID=T.ID