2016-03-29 64 views
0
INSERT INTO ACHITARI (numar_document, cod_credit, data, suma_achitata) 
SELECT Max(ACHITARI.[numar_document]) + 1 AS numar_document, 
     100 AS cod_credit, Date() AS data, 
     CREDITE.[valoare_credit]/CREDITE.[durata_in_luni] AS suma_achitata 
FROM ACHITARI, CREDITE 
WHERE CREDITE.cod_credit = 100; 

你好,我試圖運行上面的查詢。我必須使用來自2個不同表格的數據在ACHITARI表中插入一個新行。我正在收到an errorMicrosoft Access INSERT INTO聲明

在問這個問題之前,我已經搜索了很多,我發現它與Max函數有關...關於組函數的一些事情,但我真的不明白。我希望你們能幫助我。提前致謝!

+1

** Thumb的規則:**當你在'Select'中有'聚合'功能時,'非聚合'列應該出現在'Group by'中 –

回答

0

想必,你打算是這樣的:

INSERT INTO ACHITARI (numar_document, cod_credit, data, suma_achitata) 
    SELECT maxnd+1 AS numar_document, 
      100 AS cod_credit, Date() AS data, CREDITE.[valoare_credit]/CREDITE.[durata_in_luni] AS suma_achitata 
FROM (SELECDT MAX(numar_document) as maxnd FROM ACHITARI) as a, CREDITE 
WHERE CREDITE.cod_credit = 10; 

但是,你也許應該使用counter柱(身份),所以數據庫會自動保持計數器是最新的。

+0

謝謝!這工作!我會進一步研究你的解決方案,以便提高我的數據庫技能。我很感激! –