Sql Server Read text file with varying numbers of fields


February 2019


17 time


How can I read variable width records into Sql Server? In my delimted text file, each record can have a varying number of fields - there are 20 core fields, and then a repeating set of extra fields. So a record will have a minimum of 20 fields but could have 200 fields. There isn't a row of FieldNames at the start of the file.

I'm currently using Bash to add a row 0 with unique field names, and I then pad out each record to have the right number of delimiters, ie I create a heap of dummy empty fields. I then read that file as normal into Sql Server using my own application.

0 answers