comma-delimited file with header and trailer rows

Naomi Nosonovsky 8,051 Reputation points
2022-06-14T18:05:26.843+00:00

Hi everybody,

I have a csv file with the addition of header and trailer rows. Can you please point me to the clearly written blog / tutorial as how to deal with that (or explain the steps for newbie)? I'd like to load data into 3 separate tables.

Thanks in advance.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,322 questions
SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,628 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Tom Phillips 17,741 Reputation points
    2022-06-14T18:28:39.34+00:00

    Although there are ways to do this in SSIS, I find it much easier and simpler to just import all csv files into a "staging" table with all varchar fields, then use TSQL INSERT/UPDATE/MERGE in a proc to put the contents into the target table(s). This way you can skip the header/footer and process them separately in your TSQL commands.

    1 person found this answer helpful.

  2. Yitzhak Khabinsky 26,296 Reputation points
    2022-06-14T20:29:19.557+00:00

    Hi @Anonymous ,

    Alternatively, you can use SSIS Script Component as a Source.
    You would need to write there some c# code to filter out not need lines from the input .csv file.

    0 comments No comments

  3. ZoeHui-MSFT 39,671 Reputation points
    2022-06-15T02:01:30.65+00:00

    Hi @Anonymous ,

    Like YitzhakKhabinsky mentioned you could use C# to do that.

    A simple tutorial for your reference below.

    Import-a-Flat-file-with-Header-and-Detail-Rows-in

    Regards,

    Zoe


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.