SQL UPDATE查询不使用空变量

时间:2017-06-29 07:58:19

标签: sql ms-access access-vba ado

我已经做了很多寻找这个问题的答案,但我很难过......

我正在尝试编写一个SQL UPDATE查询,将数据从一个记录传输到另一个记录。我创建了一个ADODB记录集,用于保存输入到表单中的当前数据。然后我运行UPDATE SQL查询,将记录集的字段名称放入UPDATE查询中的相应字段。

当原始数据中没有空值时,它工作正常,但是当记录包含空值时,我得到一个运行时错误3144“SQL中的语法错误”。 我试过把''围绕所有变量,但这给了我一个数据类型转换错误,因为我正在更新的字段是数字数据类型而不是文本。

非常感谢。

'copy data from current event to any procedures that occured on the same day to keep the data in sync

            SQL4 = "SELECT tbl_AdmissionData.AdmFormID, tbl_AdmissionData.TeleformID, tbl_AdmissionData.DataEntryMode, tbl_AdmissionData.PatientID, tbl_AdmissionData.Clinic, tbl_AdmissionData.ClinicID, tbl_AdmissionData.ProcedureDate, tbl_AdmissionData.EventID, tbl_AdmissionData.CHx_CAD, tbl_AdmissionData.CHx_MI, tbl_AdmissionData.CHx_PCI, tbl_AdmissionData.CHx_CABG, tbl_AdmissionData.CHx_HF, tbl_AdmissionData.CHx_AF, tbl_AdmissionData.CHx_ValveDisease, tbl_AdmissionData.Sympt_Angina, tbl_AdmissionData.Sympt_ChestPain, tbl_AdmissionData.Sympt_Dyspnoea, tbl_AdmissionData.Sympt_Syncope, tbl_AdmissionData.Sympt_Palpitations, " _
                & "tbl_AdmissionData.Sympt_Asymptomatic , tbl_AdmissionData.Sympt_Other, tbl_AdmissionData.Sympt_Oth_Specify, tbl_AdmissionData.RF_Smoker, tbl_AdmissionData.RF_Smoker_Status, tbl_AdmissionData.RF_HTN, tbl_AdmissionData.RF_Chol, tbl_AdmissionData.RF_DM, tbl_AdmissionData.RF_DM_Rx, tbl_AdmissionData.RF_FamHxCAD, tbl_AdmissionData.PMHx_CKD, tbl_AdmissionData.PMHx_CKD_Rx, tbl_AdmissionData.PMHx_Stroke, tbl_AdmissionData.PMHx_CVD , tbl_AdmissionData.PMHx_PVD, tbl_AdmissionData.PMHx_DVT_PE, tbl_AdmissionData.PMHx_LungDisease, " _
                & "tbl_AdmissionData.PMHx_LD_Rx , tbl_AdmissionData.PMHx_LiverDisease, tbl_AdmissionData.PMHx_Mobility, tbl_AdmissionData.PMHx_Malignancy, tbl_AdmissionData.PMHx_Bleeding, tbl_AdmissionData.PMHx_GI, tbl_AdmissionData.PMHx_Bleed_Recent, tbl_AdmissionData.PMHx_Transf_Recent, tbl_AdmissionData.PMHx_Transf_Probs, tbl_AdmissionData.PMHx_Surgery_Recent, tbl_AdmissionData.PMHx_Surgery_Planned, tbl_AdmissionData.Fem_Menopause, tbl_AdmissionData.Fem_Pregnancy, tbl_AdmissionData.Fem_Pregnancy_CVD, tbl_AdmissionData.Fem_Pregnancy_GDM, tbl_AdmissionData.Med_Statin, tbl_AdmissionData.Med_Lipid_Other, tbl_AdmissionData.Med_ACE_ARB, " _
                & "tbl_AdmissionData.Med_BB , tbl_AdmissionData.Med_CCA, tbl_AdmissionData.Med_OHG, tbl_AdmissionData.Med_Injectable, tbl_AdmissionData.Med_NOAC, tbl_AdmissionData.Med_NOAC_Type, tbl_AdmissionData.Med_NOAC_Dose, tbl_AdmissionData.Med_Aspirin, tbl_AdmissionData.Med_P2Y12, tbl_AdmissionData.Med_P2Y12_Type, tbl_AdmissionData.Path_Trop, tbl_AdmissionData.Path_Creat, tbl_AdmissionData.Path_eGFR, tbl_AdmissionData.Path_Na, tbl_AdmissionData.Path_K, tbl_AdmissionData.Path_Hb, tbl_AdmissionData.Path_Plt, tbl_AdmissionData.Path_WCC, tbl_AdmissionData.Path_pH, tbl_AdmissionData.Path_INR, tbl_AdmissionData.Path_BHCG " _
                & "FROM tbl_AdmissionData " _
                & "WHERE (((tbl_AdmissionData.EventID)=" & CurrEvID & "));"

                rsSyncEvent.Open SQL4, CurrentProject.Connection, adOpenStatic, adLockOptimistic

            SQL5 = " UPDATE tbl_AdmissionData SET tbl_AdmissionData.DataEntryMode = '" & CurrEvID & "', tbl_AdmissionData.CHx_CAD = " & rsSyncEvent!CHx_CAD & ", tbl_AdmissionData.CHx_MI = " & rsSyncEvent!CHx_MI & ", tbl_AdmissionData.CHx_PCI = " & rsSyncEvent!CHx_PCI & ", tbl_AdmissionData.CHx_CABG = " & rsSyncEvent!CHx_CABG & ", tbl_AdmissionData.CHx_HF = " & rsSyncEvent!CHx_HF & ", tbl_AdmissionData.CHx_AF = " & rsSyncEvent!CHx_AF & ", tbl_AdmissionData.CHx_ValveDisease = " & rsSyncEvent!CHx_ValveDisease & ", tbl_AdmissionData.Sympt_Angina = " & rsSyncEvent!Sympt_Angina & ", " _
                & "tbl_AdmissionData.Sympt_ChestPain = " & rsSyncEvent!Sympt_ChestPain & ", tbl_AdmissionData.Sympt_Dyspnoea = " & rsSyncEvent!Sympt_Dyspnoea & ", tbl_AdmissionData.Sympt_Syncope = " & rsSyncEvent!Sympt_Syncope & ", tbl_AdmissionData.Sympt_Palpitations = " & rsSyncEvent!Sympt_Palpitations & ", tbl_AdmissionData.Sympt_Asymptomatic = " & rsSyncEvent!Sympt_Asymptomatic & ", tbl_AdmissionData.Sympt_Other = '" & rsSyncEvent!Sympt_Other & "', tbl_AdmissionData.Sympt_Oth_Specify = '" & rsSyncEvent!Sympt_Oth_Specify & "', tbl_AdmissionData.RF_Smoker = " & rsSyncEvent!RF_Smoker & ", " _
                & "tbl_AdmissionData.RF_Smoker_Status = " & rsSyncEvent!RF_Smoker_Status & ", tbl_AdmissionData.RF_HTN = " & rsSyncEvent!RF_HTN & ", tbl_AdmissionData.RF_Chol = " & rsSyncEvent!RF_Chol & ", tbl_AdmissionData.RF_DM = " & rsSyncEvent!RF_DM & ", tbl_AdmissionData.RF_DM_Rx = " & rsSyncEvent!RF_DM_Rx & ", tbl_AdmissionData.RF_FamHxCAD = " & rsSyncEvent!RF_FamHxCAD & ", tbl_AdmissionData.PMHx_CKD = " & rsSyncEvent!PMHx_CKD & ", tbl_AdmissionData.PMHx_CKD_Rx = " & rsSyncEvent!PMHx_CKD_Rx & ", tbl_AdmissionData.PMHx_Stroke = " & rsSyncEvent!PMHx_Stroke & ", " _
                & "tbl_AdmissionData.PMHx_CVD = " & rsSyncEvent!PMHx_CVD & ", tbl_AdmissionData.PMHx_PVD = " & rsSyncEvent!PMHx_PVD & ", tbl_AdmissionData.PMHx_DVT_PE = " & rsSyncEvent!PMHx_DVT_PE & ", tbl_AdmissionData.PMHx_LungDisease = " & rsSyncEvent!PMHx_LungDisease & ", tbl_AdmissionData.PMHx_LD_Rx = " & rsSyncEvent!PMHx_LD_Rx & ", tbl_AdmissionData.PMHx_LiverDisease = " & rsSyncEvent!PMHx_LiverDisease & ", tbl_AdmissionData.PMHx_Mobility = " & rsSyncEvent!PMHx_Mobility & ", tbl_AdmissionData.PMHx_Malignancy = " & rsSyncEvent!PMHx_Malignancy & ", " _
                & "tbl_AdmissionData.PMHx_Bleeding = " & rsSyncEvent!PMHx_Bleeding & ", tbl_AdmissionData.PMHx_GI = " & rsSyncEvent!PMHx_GI & ", tbl_AdmissionData.PMHx_Bleed_Recent = " & rsSyncEvent!PMHx_Bleed_Recent & ", tbl_AdmissionData.PMHx_Transf_Recent = " & rsSyncEvent!PMHx_Transf_Recent & ", tbl_AdmissionData.PMHx_Transf_Probs = " & rsSyncEvent!PMHx_Transf_Probs & ", tbl_AdmissionData.PMHx_Surgery_Recent = " & rsSyncEvent!PMHx_Surgery_Recent & ", tbl_AdmissionData.PMHx_Surgery_Planned = " & rsSyncEvent!PMHx_Surgery_Planned & ", " _
                & "tbl_AdmissionData.Fem_Menopause = " & rsSyncEvent!Fem_Menopause & ", tbl_AdmissionData.Fem_Pregnancy = " & rsSyncEvent!Fem_Pregnancy & ", tbl_AdmissionData.Fem_Pregnancy_CVD = " & rsSyncEvent!Fem_Pregnancy_CVD & ", tbl_AdmissionData.Fem_Pregnancy_GDM = " & rsSyncEvent!Fem_Pregnancy_GDM & ", tbl_AdmissionData.Med_Statin = " & rsSyncEvent!Med_Statin & ", tbl_AdmissionData.Med_Lipid_Other = " & rsSyncEvent!Med_Lipid_Other & ", tbl_AdmissionData.Med_ACE_ARB = " & rsSyncEvent!Med_ACE_ARB & ", tbl_AdmissionData.Med_BB = " & rsSyncEvent!Med_BB & ", " _
                & "tbl_AdmissionData.Med_CCA = " & rsSyncEvent!Med_CCA & ", tbl_AdmissionData.Med_OHG = " & rsSyncEvent!Med_OHG & ", tbl_AdmissionData.Med_Injectable = " & rsSyncEvent!Med_Injectable & ", tbl_AdmissionData.Med_NOAC = " & rsSyncEvent!Med_NOAC & ", tbl_AdmissionData.Med_NOAC_Type = " & rsSyncEvent!Med_NOAC_Type & ", tbl_AdmissionData.Med_NOAC_Dose = '" & rsSyncEvent!Med_NOAC_Dose & "', tbl_AdmissionData.Med_Aspirin = " & rsSyncEvent!Med_Aspirin & ", tbl_AdmissionData.Med_P2Y12 = " & rsSyncEvent!Med_P2Y12 & ", " _
                & "tbl_AdmissionData.Med_P2Y12_Type = " & rsSyncEvent!Med_P2Y12_Type & ", tbl_AdmissionData.Path_Trop = " & rsSyncEvent!Path_Trop & ", tbl_AdmissionData.Path_Creat = " & rsSyncEvent!Path_Creat & ", tbl_AdmissionData.Path_eGFR = " & rsSyncEvent!Path_eGFR & ", tbl_AdmissionData.Path_Na = " & rsSyncEvent!Path_Na & ", tbl_AdmissionData.Path_K = " & rsSyncEvent!Path_K & ", tbl_AdmissionData.Path_Hb = " & rsSyncEvent!Path_Hb & ", tbl_AdmissionData.Path_Plt = " & rsSyncEvent!Path_Plt & ", tbl_AdmissionData.Path_WCC = " & rsSyncEvent!Path_WCC & ", tbl_AdmissionData.Path_pH = " & rsSyncEvent!Path_pH & ", tbl_AdmissionData.Path_INR = " & rsSyncEvent!Path_INR & ", tbl_AdmissionData.Path_BHCG = " & rsSyncEvent!Path_BHCG & " " _
                & "WHERE (((tbl_AdmissionData.EventID)= " & rsEvents!EventID & "));"


                dbs.Execute SQL5, dbFailOnError

0 个答案:

没有答案