语法错误 - 将数据复制到新表中

时间:2016-07-13 11:09:29

标签: max

我遇到了Microsoft Access中的代码问题

我想将现有表中列的数据复制到新表中,然后将详细信息附加到下一个投资组合的新表底部

不需要列标题。我基本上想要复制所有列

CODE

SELECT Date, PCode, Security, Units, BarVal, BarPrice, MktPrice 
INTO "2010 extract - Feb"
FROM BarePortHistory
WHERE BarePortHistory.Pcode ="SGXEE1"
ORDER BY BarePortHistory.Date

INSERT INTO 2010 extract - Feb (Date, PCode, Security, Units, BarVal, BarPrice, MktPrice)
SELECT Date, PCode, Security, Units, BarVal, BarPrice, MktPrice 
FROM BarePortHistory
WHERE BarePortHistory.Pcode ="RTXDG1"
ORDER BY BarePortHistory.Date

INSERT INTO 2010 extract - Feb(Date, PCode, Security, Units, BarVal, BarPrice, MktPrice)
SELECT Date, PCode, Security, Units, BarVal, BarPrice, MktPrice 
FROM BarePortHistory
WHERE BarePortHistory.Pcode ="SPXUY1"
ORDER BY BarePortHistory.Date

是否使用了引号?

3 个答案:

答案 0 :(得分:1)

  1. 由几个单词组成的表名(不推荐!) 应该用方括号括起来:[2010 extract - Feb]
  2. 从一个表中选择所有数据,然后使用Or包含与任一条件匹配的数据。

    SELECT Date, PCode, Security, Units, BarVal, BarPrice, MktPrice 
    INTO [2010 extract - Feb]
    FROM BarePortHistory
    WHERE BarePortHistory.Pcode ="SGXEE1" OR BarePortHistory.Pcode ="RTXDG1" OR BarePortHistory.Pcode ="SPXUY1"
    ORDER BY BarePortHistory.Date
    

答案 1 :(得分:0)

插入new_table_Name(field1,field2 ....) 从old_table_name中选择field1,field2 .... 条件

将数据插入表时应该没有ORDER BY。试试这个

答案 2 :(得分:0)

正如马兰所说,试着改变

INTO "2010 extract - Feb"

INTO [2010 extract - Feb]

在WHERE子句中使用引号应使用单引号。

像这样:

WHERE BarePortHistory.Pcode ='SGXEE1'