What is wrong with this sql expression?

in access I do this:

insert into accounts_changes 
 (select * 
  from accounts 
  where [Agency Code] 
  in (select * from tableimport))

he says he doesn't like this INSERT statement

update:

sSql = "insert into accounts_changes (select * from Accounts where [Agency Code] in (select [Agency Code] from tableimport))"

I did what I said and it still gives me the same error message

syntax error in INSERT INTO statement

when i do this:

ssql = "select [Agency Code] from tableimport"
CurrentDb.Execute ssql

he says CANNOT FULFILL THE REQUEST CHOICE

+3
source share
5 answers

This part may mislead you:

ssql = "select [AgencyCode] from tableimport"
CurrentDb.Execute ssql

"" (INSERT, DELETE, UPDATE SELECT INTO). Execute (SELECT), , # 3065, " ". , SELECT - . SELECT, SQL View .

[AgencyCode]... . ?

, INSERT , . :

insert into accounts_changes
select * 
from Accounts
where [Agency Code] in (
    select [Agency Code] from tableimport)

, , account_changes. , , @pcent.

+2

:

select *
from accounts
where [Agency Code] in (select * from tableimport)

IN. - :

select *
from accounts
where [Agency Code] in (select [Agency Code] from tableimport)

tableimport. .

+14

You probably need to select the agency code from tableimport instead of *.

+3
source

You must specify the column that you want to find in tableimportinner select.

In addition, you can declare the fields of the inserted table and the returned fields:

INSERT INTO TABLE_EXAMPLE (A, B) SELECT AA, BB FROM TABLE_ORIGIN
+2
source

this worked:

insert into accounts_changes select * from Accounts where [Agency Code] in (select [Agency Code] from tableimport)
-2
source

Source: https://habr.com/ru/post/1749084/


All Articles