合并2个字段并插入表中

时间:2014-06-19 14:22:31

标签: vba access-vba ms-access-2010

嗨我想在我的输出表中插入值 在我的输入表中有

  

额外利润

     

10 20

当我插入到我的输出表中时,它应该连接为

  

成本

     

1020

sub test() 
Dim db As DAO.Database 
Dim rst As DAO.Recordset 
Set db = CurrentDb 
db. execut "Insert into OUTPUT_TBL (DESCRIPTION,COST,DEBIT,CREDIT) " & _
           " SELECT INPUT.DESCRIPTION,((INPUT.PROFIT)+(INPUT.EXTRA)) AS COST," & _
           "        IIF(EXTERNAL.SOLUTION='DEBIT',(AMOUNT),0) as DEBIT, " & _
           "        IIF(EXTERNAL.SOLUTION='CREDIT',(AMOUNT),0) AS CREDIT " & _
           "   FROM INPUT , EXTERNAL"
db.close 
end test 

当我尝试运行它时,我收到错误,因为运行时错误3075

1 个答案:

答案 0 :(得分:0)

夫妻问题 - 注意到一个拼写错误,它应该是db.execute""不是db.execut 此外,对于字符串连接使用&在Access SQL中。 3075表示您使用了错误的运算符。 另外,您可能还需要在SQL中添加JOIN。

例如,为了让您走上正轨:

db.execute "Insert into OUTPUT_TBL (DESCRIPTION,COST,DEBIT,CREDIT) SELECT INPUT.DESCRIPTION,((INPUT.PROFIT)&""&(INPUT.EXTRA)) AS COST,IIF(EXTERNAL.SOLUTION='DEBIT',(AMOUNT),0) as DEBIT,  IIF(EXTERNAL.SOLUTION='CREDIT',(AMOUNT),0) AS CREDIT from INPUT JOIN EXTERNAL ON INPUT.KEY=EXTERNAL.KEY"