Reputation: 806
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?
Upvotes: 0
Views: 148
Reputation: 2960
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
Upvotes: 1