Forum Discussion

naveen73's avatar
naveen73
Copper Contributor
Nov 16, 2024
Solved

Error when importing CSV file

Hi,

 

I am new at MS SQL and have the community edition in my local machine. Trying to import a CSV file but getting the following error message:

Total Defect Qty:=SUM([Defect Qty])

TITLE: Microsoft SQL Server Management Studio
------------------------------

Error inserting data into table. (Microsoft.SqlServer.Import.Wizard)

------------------------------
ADDITIONAL INFORMATION:

Error inserting data into table. (Microsoft.SqlServer.Prose.Import)

------------------------------

The given value '[name of the column]' of type String from the data source cannot be converted to type nvarchar for Column 4 [Label]. (Microsoft.Data.SqlClient)

------------------------------

String or binary data would be truncated in table '[dbo].[name of the file]', column 'Label'. Truncated value: '[name of the column '. (Microsoft.Data.SqlClient)

------------------------------
BUTTONS:

OK
------------------------------

 

Do you think you can help me please?

 

Thanks,

 

Naveen

  • It looks like contents in column Lable of the csv file is too long to insert into DB table, you should check the max size of column Label, and make sure the size of the column in DB table that import from Label is enough to contain the contents from the csv file.

    For example, if the expression MAX(LEN(E:E)) of the csv file is 137, the column definition in DB table must not less than NVARCHAR(137).

    By the way, which tool did you use to import csv?

5 Replies

  • naveen73's avatar
    naveen73
    Copper Contributor

    Hi,

     

    Thanks for taking the time to respond. The file is large and the rows that is being referred to in the message I have attached in the file.

    Any solutions are much appreciated.

    thanks,

     

    Naveen

    • rodgerkong's avatar
      rodgerkong
      Iron Contributor

      It looks like contents in column Lable of the csv file is too long to insert into DB table, you should check the max size of column Label, and make sure the size of the column in DB table that import from Label is enough to contain the contents from the csv file.

      For example, if the expression MAX(LEN(E:E)) of the csv file is 137, the column definition in DB table must not less than NVARCHAR(137).

      By the way, which tool did you use to import csv?

      • naveen73's avatar
        naveen73
        Copper Contributor

        Thanks so much.

         

        I used the Import wizard

  • olafhelper's avatar
    olafhelper
    Bronze Contributor

    > String or binary data would be truncated in table

    As the message says, you try to insert larger data then allowed by the table defintion; that's not possible.

  • rodgerkong's avatar
    rodgerkong
    Iron Contributor

    Could you post the first 5 lines of the cvs file? and definition of all columns from the target table.

Resources