Issue trying to import .dat flat file into SQL Server 2019 DB?

techresearch7777777 1,981 Reputation points
2025-03-24T21:53:03.4733333+00:00

Hello I have a flat .dat file as Source and am trying to import it into a SQL Server 2019 Database as a Table.

This .dat file FIELDTERMINATOR = '|' Vertical Pipe...and I've been trying different variations using bcp and BULK INSERT with FORMAT FILE (and tweaking things) but still unsuccessful.

Looks like my issue has something to do with the Final Column in the .dat file with LF (Line Feed?) as I've provided image shot here in my question.

The black bar (redacted column name) in the image is the Source .dat file desired "Final_Column_Name" (and similarly the other end Target destination Table).

But as you notice the .dat file also has an extra empty blank Column after this "Final_Column_Name"...am trying to skip/not include during import of this blank extra column or whatever it takes to get the import to succeed and then do clean up afterwards).

(1st line item is actual Column names header and the 2nd line and on wards below are the rows to be imported and notice no actual data in row 2 but still need to include in the overall import since the other columns in this row 2 does have data)

Like I mentioned something to do related to the final 2 columns at the end along with the row terminator in the format file...any thoughts on how I can get it to import like I mentioned at the very least and then clean up afterwards or straight up fix would be better if possible.

Thanks in advance.

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
175 questions
{count} votes

Accepted answer
  1. LiHongMSFT-4306 31,546 Reputation points
    2025-03-25T02:27:47.01+00:00

    Hi @techresearch7777777

    If the last column contains free-form text with line breaks, BULK INSERT might misinterpret these as row terminators, leading to data misalignment.

    Also, try adjusting ROWTERMINATOR for LF/CRLF mismatches.

    Best regards,

    Cosmog


    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".

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Olaf Helper 46,551 Reputation points
    2025-03-25T07:10:50.1633333+00:00

    but still unsuccessful.

    "Unsuccessful" means what in detail? Do you get any error message?

    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.