Access数据库追加查询无效过程调用

时间:2019-01-27 18:12:50

标签: sql ms-access

我正在尝试运行直到现在为止运行良好的追加查询(我每月运行一次查询)。即使没有任何更改,我现在也会收到“无效的过程调用”错误。基础的select查询运行正常。

下面是append查询的代码-

INSERT INTO 
    Audit_Vsurvey_All_Data_t 
    ( 
        Department, 
        LAST_NAME, 
        FIRST_NAME, 
        [Last Name], 
        [First Name], 
        [CPM ID], 
        [HP Author], 
        Provider, 
        [Chart ID], 
        Audit_Date, 
        Admit_Date, 
        [Question Group], 
        HP_Contains_Allergies, 
        HP_Contains_Assessment, 
        HP_Contains_Chief_Complaint, 
        HP_Vitals, 
        HP_Contains_Family_History, 
        HP_Contains_HX_Present_Illness, 
        HP_Contains_Diagnostic_Tests, 
        HP_Contains_Medications, 
        HP_Contains_Medical_History, 
        HP_Contains_Surgical_History, 
        HP_Contains_Review_Of_Systems, 
        HP_Contains_Social_History, 
        HP_Contains_Treatment_Plan, 
        HP_Documented_In_30_Days, 
        Charted_Within_24
    ) 
SELECT 
    [TT2870-LA Active].Department_Name & " " & [TT2870-LA Active].SECTION_NAME AS Department, 
    [TT2870-LA Active].LAST_NAME, 
    [TT2870-LA Active].FIRST_NAME, 
    [Vsurvey data to NameSplit].[Last Name],
    [Vsurvey data to NameSplit].[First Name],
    [TT2870-LA Active].[CPM ID], 
    [Vsurvey data to NameSplit].Author, 
    [Vsurvey data to NameSplit].Provider, 
    [Vsurvey data to NameSplit].[Chart ID], 
    [Vsurvey data to NameSplit].Audit_Date, 
    [Vsurvey data to NameSplit].Admit_Date, 
    [Vsurvey data to NameSplit].[Question Group], 
    [Vsurvey data to NameSplit].[H&P contains allergies], 
    [Vsurvey data to NameSplit].[H&P contains assessment/impression], 
    [Vsurvey data to NameSplit].[H&P contains chief complaint], 
    [Vsurvey data to NameSplit].[H&P contains current physical examination], 
    [Vsurvey data to NameSplit].[H&P contains family history], 
    [Vsurvey data to NameSplit].[H&P contains history of present illness], 
    [Vsurvey data to NameSplit]. [H&P contains labs/diagnostic test results], 
    [Vsurvey data to NameSplit].[H&P contains medications], 
    [Vsurvey data to NameSplit].[H&P contains past medical history], 
    [Vsurvey data to NameSplit].[H&P contains past surgical history], 
    [Vsurvey data to NameSplit].[H&P contains review of systems], 
    [Vsurvey data to NameSplit].[H&P contains social history], 
    [Vsurvey data to NameSplit].[H&P contains the treatment plan], 
    [Vsurvey data to NameSplit].[H&P is was documented less than 30 days from admission date_], 
    [Vsurvey data to NameSplit].[H&P present within 24 hours of admission] 
FROM 
    [Vsurvey data to NameSplit] LEFT JOIN [TT2870-LA Active] ON 
    [Vsurvey data to NameSplit].[Last Name] = [TT2870-LA Active].LAST_NAME AND 
    [Vsurvey data to NameSplit].LastSplit = [TT2870-LA Active].FIRST_NAME 
WHERE
    [Vsurvey data to NameSplit].Audit_Date Between #10/1/2018# And #12/31/2018#

由于我无法发布数据,有没有一种方法可以查看上面的代码来说明导致错误的原因。

非常感谢!

1 个答案:

答案 0 :(得分:0)

使用适当的缩进格式格式化SQL代码会发现一些奇怪的地方,我在下面的代码中对此进行了注释:

INSERT INTO 
    Audit_Vsurvey_All_Data_t 
    ( 
        Department, 
        LAST_NAME, 
        FIRST_NAME, 
        [Last Name], 
        [First Name], 
        [CPM ID], 
        [HP Author], 
        Provider, 
        [Chart ID], 
        Audit_Date, 
        Admit_Date, 
        [Question Group], 
        HP_Contains_Allergies, 
        HP_Contains_Assessment, 
        HP_Contains_Chief_Complaint, 
        HP_Vitals, 
        HP_Contains_Family_History, 
        HP_Contains_HX_Present_Illness, 
        HP_Contains_Diagnostic_Tests, 
        HP_Contains_Medications, 
        HP_Contains_Medical_History, 
        HP_Contains_Surgical_History, 
        HP_Contains_Review_Of_Systems, 
        HP_Contains_Social_History, 
        HP_Contains_Treatment_Plan, 
        HP_Documented_In_30_Days, 
        Charted_Within_24
    ) 
SELECT 
    [TT2870-LA Active].Department_Name & " " & [TT2870-LA Active].SECTION_NAME AS Department, 
    [TT2870-LA Active].LAST_NAME, 
    [TT2870-LA Active].FIRST_NAME, 
    [Vsurvey data to NameSplit].[Last Name],
    [Vsurvey data to NameSplit].[First Name],
    [TT2870-LA Active].[CPM ID], 
    [Vsurvey data to NameSplit].Author, 
    [Vsurvey data to NameSplit].Provider, 
    [Vsurvey data to NameSplit].[Chart ID], 
    [Vsurvey data to NameSplit].Audit_Date, 
    [Vsurvey data to NameSplit].Admit_Date, 
    [Vsurvey data to NameSplit].[Question Group], 
    [Vsurvey data to NameSplit].[H&P contains allergies], 
    [Vsurvey data to NameSplit].[H&P contains assessment/impression], 
    [Vsurvey data to NameSplit].[H&P contains chief complaint], 
    [Vsurvey data to NameSplit].[H&P contains current physical examination], 
    [Vsurvey data to NameSplit].[H&P contains family history], 
    [Vsurvey data to NameSplit].[H&P contains history of present illness], 
    [Vsurvey data to NameSplit]. [H&P contains labs/diagnostic test results], 
                                ^------- Extra space here
    [Vsurvey data to NameSplit].[H&P contains medications], 
    [Vsurvey data to NameSplit].[H&P contains past medical history], 
    [Vsurvey data to NameSplit].[H&P contains past surgical history], 
    [Vsurvey data to NameSplit].[H&P contains review of systems], 
    [Vsurvey data to NameSplit].[H&P contains social history], 
    [Vsurvey data to NameSplit].[H&P contains the treatment plan], 
    [Vsurvey data to NameSplit].[H&P is was documented less than 30 days from admission date_], 
                                                                Should this be here? -------^
    [Vsurvey data to NameSplit].[H&P present within 24 hours of admission] 
FROM 
    [Vsurvey data to NameSplit] LEFT JOIN [TT2870-LA Active] ON 
    [Vsurvey data to NameSplit].[Last Name] = [TT2870-LA Active].LAST_NAME AND 
    [Vsurvey data to NameSplit].LastSplit = [TT2870-LA Active].FIRST_NAME 
WHERE
    [Vsurvey data to NameSplit].Audit_Date Between #10/1/2018# And #12/31/2018#

如果以上建议不能解决问题,那么我只能建议对于每个附加字段,将select语句中的表达式临时替换为该字段的默认值,然后重复直到查询评估无错误为止。

例如,要测试第一个字段是否是导致问题的原因,请临时将附加值更改为构成该字段有效数据的默认字符串值,例如:

INSERT INTO 
    Audit_Vsurvey_All_Data_t 
    ( 
        Department, 
        LAST_NAME, 
        FIRST_NAME, 
        -- ... < more fields > ...
        Charted_Within_24
    ) 
SELECT 
    "Default Department" AS Department, -- Temporarily change to a default value
    [TT2870-LA Active].LAST_NAME, 
    [TT2870-LA Active].FIRST_NAME, 
    -- ... < more fields > ...
    [Vsurvey data to NameSplit].[H&P present within 24 hours of admission] 
FROM 
    [Vsurvey data to NameSplit] LEFT JOIN [TT2870-LA Active] ON 
    [Vsurvey data to NameSplit].[Last Name] = [TT2870-LA Active].LAST_NAME AND 
    [Vsurvey data to NameSplit].LastSplit = [TT2870-LA Active].FIRST_NAME 
WHERE
    [Vsurvey data to NameSplit].Audit_Date Between #10/1/2018# And #12/31/2018#

这将使您能够确定是哪个字段引起了错误,以便您可以进行进一步调查。