2017-04-14 1 views
0

을 사용하여 SQL 테이블/데이터를 MS Access로 내보내기 SQL Server 내보내기/가져 오기 관리자를 사용하여 SQL 테이블을 ms 액세스 파일로 내보내는 방법은 이미 들었지만 동적으로 사용하지는 않습니다. 저장 프로 시저에서이 작업을 수행하는 방법은 무엇입니까? 쿼리를 실행하고 내보내기/가져 오기 관리자와 같은 ms 액세스 파일에 테이블로 저장하지만 코드와 유사합니까?저장 프로 시저

미리 감사드립니다.

답변

1

SSIS 패키지를 만들고 저장하여 Sql Server에서 Access로 가져 오기/내보내기 작업을 수행하고 필요한 매개 변수로 저장 프로 시저에서 호출 할 수 있습니다.

+0

Select - Statement를 동적으로 변경해야합니다. 저장 한 후에 코드를 통해 .dtsx의 쿼리를 변경하는 방법이 있습니까? –

+0

SP에서 SSIS 패키지를 호출하는 동안 변수의 선택 쿼리를 SSIS 패키지에 전달할 수 있으며 해당 변수를 SSIS 원본의 명령으로 사용할 수 있습니다. SSIS에서 사용자 지정 작업을 만들어 ETL 작업을 수행 할 수도 있습니다. – Kapil

0

시도해 볼 수있는 몇 가지 사항이 있다고 가정합니다. SSIS에 액세스 할 수 있으면 작업을 수행 할 것입니다. 가져 오기/내보내기 마법사를 사용하여 작업을 수행 할 수 있습니다.

https://docs.microsoft.com/en-us/sql/integration-services/import-export-data/start-the-sql-server-import-and-export-wizard

구성 및 테스트

To import data into an existing table in the Access database, the INSERT OPENQUERY(...) syntax must be used. For example, if the SQL Server table is called SrvTable and the Access table is called Table1 and both tables contain the same columns, the following SQL script will copy the data from the SQL Server table into the Access table. 

INSERT OPENQUERY(AccessDB, 'SELECT * FROM Table1') 
SELECT * FROM SrvTable 

If necessary, you can also update existing data in the Access database from the SQL Server using the UPDATE OPENQUERY syntax, as seen below. 

UPDATE OPENQUERY(AccessDB, 'SELECT * FROM Table1') 
SET Col1 = 'Testing...' 

You can also delete data from the Access database using the DELETE OPENQUERY syntax. (Note the escaped single-quotes [''] inside the OPENQUERY statement.) 

DELETE OPENQUERY(AccessDB, 'SELECT * FROM Table1 WHERE Col1 = ''Testing...''') 

Finally, create a stored procedure that utilizes any combination of the OPENQUERY statements to accomplish your data import task. For example, to copy all records from the SrvTable to Table1 the Access database, then update Col1 to "Testing...", use the following SQL script. 

CREATE PROCEDURE CopyToTable1 AS BEGIN 
INSERT OPENQUERY(AccessDB, 'SELECT * FROM Table1') 
SELECT * FROM SrvTable 

UPDATE OPENQUERY(AccessDB, 'SELECT * FROM Table1') 
SET Col1 = 'Testing...' 
END 

마지막으로 Access 데이터베이스에 데이터 가져 오기 연결된 서버

Connect to the SQL Server and create a new linked server. This can be done using the following SQL script, which will create a new liked server called "AccessDB." (The value after @datasrc is the path to the Access database on the computer that is running SQL Server.) 

EXEC sp_addlinkedserver 
@server = 'AccessDB', 
@provider = 'Microsoft.Jet.OLEDB.4.0', 
@srvproduct = 'OLE DB Provider for Jet', 
@datasrc = 'C:\Path\to\Access\Database.mdb' 
GO 

Test the linked server by selecting from an existing table in the Access database (this is optional). For example, if there is a table called "Table1" in the Access database, the following SQL script will select all data from it. 

SELECT * 
FROM OPENQUERY(AccessDB, 'SELECT * FROM Table1') 

If necessary, you can remove the linked server using the sp_dropserver procedure. 

EXECUTE sp_dropserver 'AccessDB' 

, ...이 옵션을 고려

Follow These Steps: (Video also available) 
1. Open control Panel 
2. open “ODBC” from “Administrative tools” 
3. Create a Data Source for the SQL database from which you need to import 
4. open MS Access, Select “External Data” Tab 
5. Select “ODBC Database” 
6. In “Machine Data source” tab, select the Data Source you have created. 
7. Then you will find an Import Object window, Select the tables that you need to Import 
8. Then Press “OK” 

If you prefer to do using ADO : http://www.vb-helper.com/howto_ado_import_sql_server.html 

Else use this code: 

SELECT * FROM [ODBC;Driver=SQL Server Native Client 10.0;SERVER=Your_Server_Name;DATABASE=DB_Name;UID=User_Login;PWD=Your_Password] 

https://support.office.com/en-us/article/Import-or-link-to-SQL-Server-data-a5a3b4eb-57b9-45a0-b732-77bc6089b84e?CorrelationId=7b7e6535-5ac3-4fd1-9766-d7ebfa151046&ui=en-US&rs=en-US&ad=US&ocmsassetID=HA010200494#BM1

+0

안녕하십니까, 답변 해 주셔서 감사합니다.하지만 테이블을 완전히 가져올 수있는 방법이 있습니까? 그래서 열과 함께 –