0

I can't find out if the below is possible. I want to run an update statement in one database from another database. I know that I can save a query and run that from the master database but I thought the below would be possible

UPDATE tblOne 
 INNER JOIN tblTwo 
    ON tblOne.[TID] = tblTwo.TID 
   SET tblTwo.PC = [tblOne].[PC] 
  from tblOne in 'C:\DB.mdb' ;

Any help would be greatly appreciated

2
  • I want to know what the format is for using 'In' as part of an 'Update' statement: Commented Apr 6, 2018 at 13:55
  • Where does the 'In 'C:\DB.mdb'' go in the following: UPDATE table SET newvalue WHERE criteria; Commented Apr 6, 2018 at 13:55

2 Answers 2

1

Per the MSDN Documentation, the IN clause is only compatible when used in conjunction with the SELECT statement (i.e. Select queries), INSERT INTO statement (i.e. Append queries), or SELECT INTO statement (i.e. Make Table queries) - it cannot be used as part of an UPDATE statement.

I would suggest that you import tblOne as a linked table in the database in which you intend to execute your UPDATE query - this will also result in improved performance over the use of the IN clause.

To link the table, select Access Database from the Import panel of the External Data ribbon tab, and then select the Link option from the wizard:

enter image description here

After the table has been linked, your UPDATE statement will become simply:

UPDATE 
    tblOne INNER JOIN tblTwo ON tblOne.TID = tblTwo.TID 
SET 
    tblTwo.PC = tblOne.PC
Sign up to request clarification or add additional context in comments.

Comments

0

I think you just need to reverse what you’ve written because the table you’re updating needs to be the main table.

Try:

UPDATE tblTwo  
INNER JOIN tblOne ON tblOne.[TID] = tblTwo.TID  
SET tblTwo.PC = [tblOne].[PC] ;

Please note without a where clause you will be updating all rows.

2 Comments

The update statement works in the master db but I can't run it in the second database - so I need the 'In' to use the second database but I can't get the format of the statement correct. I'm wondering if this isn't possible and that's why I've seen people using Insert Into to get the data into the second database
Are the databases on the same database server?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.