2022年2022年旧版数据导入新版数据方法 .pdf
旧版数据导入新版数据方法.txt铁饭碗的真实含义不是在一个地方吃一辈子饭,而是一辈子到哪儿都有饭吃。就算是一坨屎,也有遇见屎壳郎的那天。所以你大可不必为今天的自己有太多担忧。 2010.01.17 龙岗数据转新版数据旧数据库类型A 旧数据库类型B 先备份新旧数据库,然后升级1. DEPART - tbDepartment 31 - 0 其它不变改表与 DOCTORUSER关联,因此要修正DOCTORUSER.DEPARTID SQL 语句如下旧数据库类型A: DELETE FROM MedImgMgrSysLG.dbo.tbDepartment; DELETE FROM EndoscopeLG.dbo.DEPART WHERE DEPARTID=-1; UPDATE EndoscopeLG.dbo.DEPART SET DEPARTID=0 WHERE DEPARTID=31; UPDATE EndoscopeLG.dbo.DOCTORUSER SET DEPARTID=0 WHERE DEPARTID=31; INSERT MedImgMgrSysLG.dbo.tbDepartment(DepartmentID, DepartmentName) SELECT DEPARTID, DEPARTDESC FROM EndoscopeLG.dbo.DEPART; 2. DOCTORUSER - tbDoctor (1)LEVELCODE - AuthCode 255 - 1023 1 - 1 2 - 563 (2)LOGINPWD - LoginPasswd (3)WORKID - WorkID DOCTORUSER.WorkID = tbDoctor.WORKID + 1000 ? (4) HIRESTATUS - HireStatus DOCTORUSER.Status = tbDoctor.HIRESTATUS - 1 (5) SEX - Sex 0 - 1 1 - 2 2 - 0 (6) DUTYID - DutyID DOCTORUSER.DutyID = tbDoctor.DUTYID - 1 (7) CNNAME - LoginName, NameCN DOCTORUSER.LoginName = tbDoctor.CNNAME DOCTORUSER.NameCN = tbDoctor.CNNAME 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 6 页 - - - - - - - - - (8) DEPARTID - DepartmentID DOCTORUSER.DepartmentID = tbDoctor.DEPARTID SQL 语句如下旧数据库类型A: 首先修改LEVELCODE 类型由 tinyint改为 int ,然后执行UPDATE EndoscopeLG.dbo.DOCTORUSER SET LEVELCODE=1023 WHERE LEVELCODE=255; UPDATE EndoscopeLG.dbo.DOCTORUSER SET LEVELCODE=563 WHERE LEVELCODE=2; UPDATE EndoscopeLG.dbo.DOCTORUSER SET SEX=SEX+1; UPDATE EndoscopeLG.dbo.DOCTORUSER SET SEX=0 WHERE SEX=3; UPDATE EndoscopeLG.dbo.DOCTORUSER SET HIRESTATUS=HIRESTATUS; UPDATE EndoscopeLG.dbo.DOCTORUSER SET DUTYID=DUTYID-1; INSERT MedImgMgrSysLG.dbo.tbDoctor(WorkID, DepartmentID, LoginName, LoginPasswd, AuthCode, HireStatus, DutyID, Sex) SELECT WORKID, DEPARTID, CNNAME, ISNULL(LOGINPWD,), LEVELCODE, ISNULL(HIRESTATUS, 0), DUTYID, SEX FROM EndoscopeLG.dbo.DOCTORUSER; 3. tbPatientInformation - PATIENTE, PATIENTSELF (1) MedicalID - PATIENTSELF.MEDICCAREID (2) InHospitalID - PATIENTSELF.INHOSPITAL (3) OutPatientID - IF (PATIENTSELF.INHOSTPITAL = NULL) IDPATIENTSELF.SICKBEDID ELSE NULL (4) CheckID - 该表的 CheckID 根据旧版数据库的版本情况,由两种可能 1 图片按 PATIENTSELF.ENDSCPID 存放的要对同一机台号的同一天的病例进行处理,生成RECORDCDNO 然后同 2 处理 2 图片按 PATIENTSELF.RECORDCDNO存放的CheckID - PATIENTSELF.RECORDCDNO (5) InstrumentID - PATIENTSELF.INSTRUMENTID (6) PatientName - PATIENTSELF.PATIENTNAME (7) Sex - PATIENTSELF.SEX 0 - 1 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 6 页 - - - - - - - - - 1 - 2 2 - 0 (8) Age - PATIENTSELF.AGE AgeType - PATIENTSELF.AGE IF PATIENTSELF.AGE 200 THEN tbPatientInformation.Age = PATIENTSELF.AGE tbPatientInformation.AgeType = 0 IF PATIENTSELF.AGE 200 AND PATIENTSELF.AGE 300 THEN tbPatientInformation.Age = PATIENTSELF.AGE - 300 tbPatientInformation.AgeType = 2 (9) Address - PATIENTSELF.ADDRESS (10) Phone - PATIENTSELF.PHONE (11) AskDepartment - PATIENTSELF.ASKDEPT (12) AskDoctor - PATIENTSELF.ASKDR (13) CheckDoctor - PATIENTSELF.CHECKDR (14) CheckDepartment - NULL (15) CheckTime - PATIENTSELF.CHECKTIME (16) ReportDoctor - PATIENTSELF.REPORTDR (17) ReportDepartment - NULL (18) ReportTime - PATIENTSELF.REPORTTIME (19) ImageCount - PATIENTSELF.IMAGECOUNT (20) CheckStatus - PATIENTSELF.CHECKSTATUS (21) CheckDesc - PATIENTSELF.CHECKDESC (22) DiagDesc - PATIENTSELF.DIAGNOSEDESC (23) PatientType - 0 (24) Fee - PATIENTE.FEE (25) AskAdvice - PATIENTE.ASKADVICE (26) CheckPos - PATIENTE.CHECKPARTDESC (27) BedID - IF (PATIENTSELF.INHOSTPITAL != NULL) IDPATIENTSELF.SICKBEDID ELSE NULL (28) OrganCount - (30) Positive - 对于有阳性的数据表特殊处理SQL 语句如下旧数据库类型A:( 龙岗 78M数据库 ) 修改 PATIENTSELF 表,将 PATIENTE中的部分字段FEE 、ASKADVICE 、CHECKPARTDESC加入其中修改 PATIENTSELF 表,加入AGETYPE 字段,类型int 修改 PATIENTSELF 表,加入OUTPAITENTID 字段,类型varchar 20 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 6 页 - - - - - - - - - 修改 PATIENTSELF 表,加入ASKDATE 字段,类型varchar 20 修改 PATIENTSELF 表,加入CHECKDAYID 字段,类型int 选中旧数据库UPDATE PATIENTSELF SET PATIENTSELF.FEE=PATIENTE.FEE, PATIENTSELF.ASKADVICE=PATIENTE.ASKADVICE, PATIENTSELF.CHECKPARTDESC=PATIENTE.CHECKPARTDESC FROM PATIENTSELF, PATIENTE WHERE PATIENTSELF.ENDSCPID=PATIENTE.ENDSCPID AND PATIENTSELF.INSTRUMENTID=PATIENTE.INSTRUMENTID; / 清除错误的数据DELETE FROM PATIENTSELF WHERE ASKTIME IS NULL; UPDATE PATIENTSELF SET AGETYPE=0 WHERE AGE200 AND AGE300; UPDATE PATIENTSELF SET SEX=SEX+1; UPDATE PATIENTSELF SET SEX=0 WHERE SEX=3; UPDATE PATIENTSELF SET OUTPAITENTID=SICKBEDID, SICKBEDID=NULL WHERE INHOSPITAL IS NULL; UPDATE PATIENTSELF SET OUTPAITENTID=SICKBEDID, SICKBEDID= WHERE INHOSPITAL=; UPDATE PATIENTSELF SET ASKDATE=LTRIM(STR(DATEPART(year, ASKTIME)+RIGHT(CAST(POWER(10,2) AS varchar)+DATEPART(month, ASKTIME),2)+RIGHT(CAST(POWER(10,2) AS varchar)+DATEPART(day, ASKTIME),2); DROP PROCEDURE UPDATECHECKDAYID; CREATE PROCEDURE UPDATECHECKDAYID INSTRUID INT AS DECLARE dayid int DECLARE patientid int-临时变量,用来保存游标值DECLARE askdate varchar(20) DECLARE oldaskdate varchar(20) set dayid=1 set oldaskdate= BEGIN TRAN - 申明事务- 申明游标为 patientid DECLARE order_cursor CURSOR FOR SELECT PATIENTID, ASKDATE FROM PATIENTSELF WHERE INSTRUMENTID=INSTRUID ORDER BY ASKDATE - 打开游标open order_cursor 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 6 页 - - - - - - - - - FETCH NEXT FROM order_cursor INTO patientid, askdate WHILE FETCH_STATUS = 0 - 返回被 FETCH 语句执行的最后游标的状态,而不是任何当前被连接打开的游标的状态。begin if askdate=oldaskdate begin set dayid=dayid+1 end else begin set dayid=1 set oldaskdate=askdate end -执行 sql 操作 UPDATE PATIENTSELF SET CHECKDAYID=dayid WHERE PATIENTID=patientid FETCH NEXT FROM order_cursor INTO patientid, askdate end COMMIT TRAN -提交CLOSE order_cursor-关闭游标DEALLOCATE order_cursor-释放游标GO 针对每一个机台号,执行EXEC UPDATECHECKDAYID INSTRUID = 1 EXEC UPDATECHECKDAYID INSTRUID = 2 EXEC UPDATECHECKDAYID INSTRUID = 3 EXEC UPDATECHECKDAYID INSTRUID = 4 EXEC UPDATECHECKDAYID INSTRUID = 5 EXEC UPDATECHECKDAYID INSTRUID = 6 EXEC UPDATECHECKDAYID INSTRUID = 7 . UPDATE PATIENTSELF SET RECORDCDNO=ASKDATE+RIGHT(CAST(POWER(10,3) AS varchar)+CHECKDAYID,3); INSERT MedImgMgrSysLG.dbo.tbPatientInformation(MedicalID, InHospitalID, OutPatientID, CheckID, InstrumentID, PatientName, Sex, Age, AgeType, Address, Phone, AskDepartment, AskDoctor, CheckDoctor, CheckTime, ReportDoctor, ReportTime, ImageCount, CheckStatus, CheckDesc, DiagDesc, PatientType, Fee, AskAdvice, CheckPos, BedID) SELECT MEDICCAREID, INHOSPITAL, OUTPAITENTID, RECORDCDNO, INSTRUMENTID, PATIENTNAME, SEX, AGE, AGETYPE, ADDRESS, PHONE, ASKDEPT, ASKDR, CHECKDR, CHECKTIME, REPORTDR, REPORTTIME, IMAGECOUNT, CHECKSTATUS, CHECKDESC, DIAGNOSEDESC, 0, FEE, ASKADVICE, CHECKPARTDESC, SICKBEDID FROM EndoscopeLG.dbo.PATIENTSELF; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 6 页 - - - - - - - - - 旧数据库类型B:( 龙岗 20M数据库 ) 4. tbPatientImage - PATIENTIMAGE 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 6 页 - - - - - - - - -