简体   繁体   中英

Where to store CSV file in SSIS file within SQL Server

I have a SSIS task in which the control flow pulls data from an external source, uploads it to CSV and modifies the rows, and then uploads the CSV file into a SQL server table.

Normally I'd keep the CSV local file on my machine and reference it there, but when deploying the SSIS package to SQL Server to run as a scheduled job that becomes no longer feasible. Additionally, I cannot create a temporary table within the SQL server as a substitute for the CSV file in this specific scenario.

Is it possible to upload a CSV file as a CSV within a SQL server? Alternatively, what is the best way to reference an externally stored CSV file or otherwise substitute a temporary CSV file within the SSIS package such as a temporary flat file?

There are several ways to achieve this. One way would be to save it on a network drive and use openrowset, openquery depending on the type of driver you have installed in the SQL server to access the csv file like a table.

see examples:

SELECT *
FROM
        OpenRowset('MSDASQL','Driver={Microsoft Access Text Driver (*.txt, *.csv)}; 
            Extended properties=''ColNameHeader=True;
            Format=Delimited;''',
            'select * from \\server1\File.csv'
        )Bas

OR

SELECT 
    *
FROM OPENROWSET(
    'Microsoft.ACE.OLEDB.12.0',
    'Text;Database=D:\NetworkLocation\;HDR=Yes;FORMAT=Delimited(;)', 
    'SELECT * FROM [File.csv]') i

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM