Gary Barrett
Gary Barrett

Reputation: 2018

From SQL Server how do I read from an MS Access database to UPDATE data in one or more table columns?

My SQL Server database table has a column that needs to be Updated with data from an MS Access file. How do I query the MS Access data to perform such an update?

Import Wizard seems to only handle Inserting of new data and not UPDATE existing data? Or am I misunderstanding how to use the wizard?

Upvotes: 8

Views: 35360

Answers (2)

Olivier Jacot-Descombes
Olivier Jacot-Descombes

Reputation: 112392

First set up a ODBC DSN in Windows. Open Control Panel > Administrative Tools > Data Sources (ODBC). Note that on 64 bit Windows, this might open the 64-bit-administrator. However, if you have a 32-bit Access, you need the 32-bit-administrator (%windir%\SysWOW64\odbcad32.exe).

Then you can link the SQL-Server tables to your access db. In the Link Tables dialog, choose "ODBC Databases()" as file type.

You can then query the linked SQL Server tables as if they were access tables.

See Configure Microsoft Access Linked Tables with a SQL Server Database

Upvotes: 4

HansUp
HansUp

Reputation: 97101

Sounds like you want to run that operation from the SQL Server side ... "pull" the Access data into SQL Server. If so, you can set up the Access file as a linked server within SQL Server. I've not done that, but have read cases where other people have. I copied these steps from How can I link a SQL Server database to MS Access using link tables in MS Access? at SQLServerPedia.

1) Open EM.
2) Goto the Server to which you want to add it as linked server.
3) Then goto security > Linked Servers section from console tree.
4) Right click on the Client area. Then New Linked Server.
5) Give a name and Specify Microsoft Jet 4.0 as Provider string.
6) Provide the location of the MDB file.
7) Click OK.

Alternatively, you could run the operation from the Access side, and push the data to SQL Server. If that could work for you, use Olivier's instructions to set up the ODBC-linked SQL Server table. Or you do it without creating a DSN: Using DSN-Less Connections.

Either way you link the table, the UPDATE statement you run from within Access might then be as simple as:

UPDATE
    linked_table AS dest
    INNER JOIN local_table AS src
    ON dest.pkey_field = src.pkey_field
SET dest.access_data = src.access_data
WHERE
    dest.access_data <> src.access_data
    OR dest.access_data Is Null;

Upvotes: 8

Related Questions