I am trying to import a flat file (fixed width fields) in to a SQL Server table. Since I need to import many files, and each file can be quite large, I want a fast way to do this.
My plan was this... I'll create an SP that imports the data in to a temp table. Then parse the individual data elements using the SubString function. Then, finally put the data where it belongs.
When I issue the following command...
Select *
From OPENROWSET('MSDASQL.1',
'Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=C:\MyFolder;',
'Select * from MyFile.txt')
I can see all my data, but the column header (field name) is the data that is in the first row of the data file.
My question is this.... How can I get the first row of the data file to import as data, not a field name?
My plan was this... I'll create an SP that imports the data in to a temp table. Then parse the individual data elements using the SubString function. Then, finally put the data where it belongs.
When I issue the following command...
Select *
From OPENROWSET('MSDASQL.1',
'Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=C:\MyFolder;',
'Select * from MyFile.txt')
I can see all my data, but the column header (field name) is the data that is in the first row of the data file.
My question is this.... How can I get the first row of the data file to import as data, not a field name?