0

我不熟悉 SQL 或 Access。

我正在使用 Access (2010) 版本的 SQL 编写 INSERT INTO 查询。

我收到以下错误(查询输入必须包含至少一个表或查询

这是我的代码

    INSERT INTO TABLE ( AsOf, Portfolio, [String A], [Number A] ) VALUES 
    (#DATE#, 
           (SELECT P.Portfolio FROM tb_data_Portfolio P  
                 WHERE IIF  ( EXISTS 
                    (SELECT Portfolio FROM tb_data_Portfolio p2 WHERE p2.Portfolio = 'Some String'), 
                    (P.Portfolio = 'Some String'), 
                    (P.Id = (SELECT px.Portfolio_Id FROM tb_sys_Portfolio_xRef px WHERE px.ext_Portfolio = 'Some String'))
             )
)    
,'String a', 'Number a');
4

1 回答 1

0

Your query should start like this (you can't mix values and SELECT in an INSERT)

INSERT INTO TABLE ( AsOf, Portfolio, [String A], [Number A] ) 
  SELECT DATE, P.Portfolio FROM tb_data_Portfolio P  
    WHERE ...;

I don't understand what you're trying to do in the WHERE clause, but I don't think you can use a subquery inside IIF(). Please explain your objectives and I'll edit my answer.

于 2013-03-25T20:24:04.403 回答