0

I am using the T-SQL Bulk Insert command to insert large text files into tables. The tables have many nvarchar columns, I found that if the text file has empty string values for any nvarchar column, bulk insert will insert NULL in that table column.

I have Googled this extensively, there are lots of people complaining about the reverse scenario (null >> empty string), and the bulk insert statement has a parameter to control this, but nothing to force empty string to be retained as empty string in the destination table. Seems like there should be some way to do this.

There is one solution involving setting default values on the nvarchar table columns, I don't want to do this as the target tables are copies from a large ERP and modifying them will cause other issues potentially. Any advice is welcome!

4
  • I have to ask, why would you want that ? Commented Oct 25, 2024 at 5:26
  • 2
    use a staging or temp table ? Commented Oct 25, 2024 at 5:41
  • 1
    Bulk insert is not known for its flexibility in general. Why not use some library to read files and control the exact in/output Commented Oct 25, 2024 at 6:20
  • Why would I want to do that? We are using a third part data integration tool to transfer entire tables of data from sap into sql server. These tables are massive, for example, ACDOCA has 658,000,000 rows. The tool cannot cope with selected from sap and inserting into sql, it takes 7 days to finish this one table. However, it can extract the data as text file speedily. So I can then bulk insert those file in a multi threaded fashion. Except bulk insert turns empty string null, which beaks downstream operations which expect empty string. Commented Nov 8, 2024 at 3:48

1 Answer 1

0

Cant be done. Solution was add defaults of empty string to the columns in the table.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.