2017-08-09 70 views
-3

我需要幫助,我需要將SQL語法轉換爲MS Access語法,但我不知道如何。SQL - 將SQL語法轉換爲MS Access的幫助

INSERT INTO SampleData2 
    SELECT 
     Object_Account, Descriptions, GL_Date, Document_Type, 
     Document_Number, Company, Subledger, Subledger_Type, ' ', 
     SUM(Actual_Amount * -1) AS TotalAmount, 
     (JE_Explantion) AS Explanation 
    FROM 
     SampleData 
    WHERE 
     CAST(Object_Account AS VARCHAR(20)) + Subledger + JE_Explantion 
      IN (SELECT CAST(Object_Account AS VARCHAR(20)) + Subledger + JE_Explantion 
       FROM SampleData 
       GROUP BY Object_Account, Subledger, JE_Explantion 
       HAVING COUNT(Object_Account) > 1) 
    GROUP BY 
     Object_Account, Descriptions, GL_Date, Document_Type, 
     Document_Number, Company, Subledger, Subledger_Type, Remarks, 
     JE_Explantion 
+0

我沒有看到任何特定供應商的零件在你的代碼... –

+1

請具體談談你試過,什麼是不工作的。 – Paolo

+0

您正在使用CAST()的問題? – SandPiper

回答

1

MS Access使用&字符串連接,不支持cast()。您可以試試:

INSERT INTO SampleData2 
    SELECT Object_Account, Descriptions, GL_Date, Document_Type, Document_Number, 
      Company, Subledger, Subledger_Type, ' ', Sum(Actual_Amount * -1) AS TotalAmount, (JE_Explantion) As Explanation 
    FROM SampleData as sd 
    WHERE EXISTS (SELECT 1 
        FROM SampleData as sd2 
        WHERE sd2.Object_Account = sd.Object_Account AND 
         sd2.Subledger = sd.Subledger AND 
         sd2.JE_Explantion = sd.JE_Explantion 
        GROUP BY Object_Account, Subledger, JE_Explantion 
        HAVING COUNT(Object_Account) > 1 
       ) 
    GROUP BY Object_Account, Descriptions, GL_Date, Document_Type, Document_Number, 
Company, Subledger, Subledger_Type, Remarks, JE_Explantion;