As I am a beginner in SQL Server and my scripting is not very polished yet. I need suggestions on the below issue.
I receive files from a remote server to my machine (around 700/day) as follows :
ABCD.100.1601310200
ABCD.101.1601310210
ABCD.102.1601310215
Naming Convention: Here the first part 'ABCD' remains the same, middle part is a sequence id which is in incremental order for every file. The last part is time stamp.
File structure The file does not have any specific extension but can be opened with notepad/excel. Therefore can be called as flat file. Each files consist of 95 columns and 20000 rows fixed with some garbage value on top 4 and bottom 4 rows of column 1.
Now, I need to make a database in SQL server where I can import data from these flat files using a scheduler. Suggestion needed.
There are probably other ways of doing this, but this is one way:
OPENROWSET(BULK '<file_name>', FORMATFILE='<format_file>'
This creates a format file to be used in the next step. The following script creates a format file in
C:\Temp\imp.fmt
based on an existing table (replaceTEST_TT
with the database you are importing to). This creates such a format file with a,
as field seperator. If the files have tab as seperator, remove the-t,
switch.Before executing this you will to reconfigure SQL Server to allow the
xp_cmdshell
stored procedure. You only need to do this once.This script assumes:
C:\Temp
C:\Temp\imp.fmt
(generated in the previous step)