Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)

I have 390 delimited text files collected from different sources. I have to load them in SQL Server. I don't want to use import and export wizard. I want to create a Bulk Copy Command Mechanishm through which data can be inserted into database.

  1. Every file has 32 columns but there are certain files in which columns are less because of inavailibility of information.
  2. Data collected from every source is different, in-terms of Specifying Spaces between data.
  3. I have searched about this online. The main confusion is in Specifying Starting & Ending Position of a particular column.
  4. How to specify a Field Terminator for a Column. Because space in between the columns is different. I am not able to guess any pattern.
  5. I want to create a table, comprising of following columns:-
    1. Path of the Control file
    2. Column (1) Starting Postion
    3. Column (1) Ending Position
    4. Column (2) Starting position
    5. Column (2) Ending Position
    6. From this table I want to create a dynamic bulk copy command that can copy all data in SQL Server.

Creating this would be really helpful for me. I am not able to see any sort of help for this on Google.

Please refer to me any google link or guide me, How can I do this. Please.



What I have tried:

BULK INSERT TblTable
FROM 'D:\PD_C1\1.txt'
WITH
(
  FIELDTERMINATOR = '','',
  ROWTERMINATOR = ''\n'',
)
Posted
Updated 17-Dec-19 5:10am

You can write a SSIS package that does it, or find a code snippet that parses it and transforms it into a SQL compatible entity that can be inserted into the database.
 
Share this answer
 
It sounds like you are dealing with fixed length files as opposed to value delimited files (i.e., comma or tab delimited). I assume this because you describe the columns as having a starting position and ending position.

If this is the case, the Almighty Google has a solution for you!
Welcome To TechBrothersIT: SSIS - How to Load Fixed Width Text File to SQL Server Table By Using SSIS Package[^]
 
Share this answer
 
Comments
Hamza Hussain 18-Dec-19 6:53am    
Thank you Very Much Sir.
I have understood it. This is exactly where I was stuck. Link is helpful.
Now I have 390 Files.
Should I create mapping of 390 Files in SSIS Package side by side or can I do it programatically ?
After this I want to Call this SSIS package in asp.net code
AFell2 18-Dec-19 17:27pm    
Is that 390 files all with distinct column mappings? That would mean you would either have to create 390 SSIS packages, or 1 SSIS package with 390 configurations. I would lean towards the latter, as you can always containerize the configurations to a JSON or xml file and pull them in at processing time to handle the column configuration.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900