Import CSV file in SQL keeping leading zero

Dimitri Garmaise 266 Reputation points

Good evening, I want to import a CSV file in SQL using Bulk import. I have a field containing the following value 010010 and that field has to remain like that in database. I have done several test but all of them have for result 10010 ---> leading zero is missing. Could someone explain what I should do to avoid that type of problem? Thanks

As requested by @Yitzhak Khabinsky

FROM 'C:\Users\xxxxx\Downloads\Sviluppo C#\SQL_Dati per tests\ScenariosUploadCSV.csv' WITH ( CODEPAGE = '65001', FORMAT = 'CSV', FIELDQUOTE = '', FIRSTROW = 2, FIELDTERMINATOR = ';', ROWTERMINATOR = '\n', TABLOCK )


A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
565 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
9,880 questions
{count} votes

Accepted answer
  1. Erland Sommarskog 78,826 Reputation points MVP

    Sounds like the data type of the column is int. You will need a string data type for the leading zero to be maintained.

    Else, to assist with BULK INSERT questions, it helps a lot if you include:

    1. The CREATE TABLE statement for your target table.
    2. You attach a sample file that demonstrates the problem. (We need to see the exact bytes, so including it as text in the post is not a good idea.)
    3. Any format file you are using.
    4. The complete statement as you are running it right now.
    0 comments No comments

0 additional answers

Sort by: Most helpful