Error converting data types when importing from Excel to SQL Server 2008

前端 未结 6 1064
暗喜
暗喜 2020-12-03 06:00

Every time that I try to import an Excel file into SQL Server I\'m getting a particular error. When I try to edit the mappings the default value for all numerical fields is

6条回答
  •  醉酒成梦
    2020-12-03 06:27

    When Excel finds mixed data types in same column it guesses what is the right format for the column (the majority of the values determines the type of the column) and dismisses all other values by inserting NULLs. But Excel does it far badly (e.g. if a column is considered text and Excel finds a number then decides that the number is a mistake and insert a NULL instead, or if some cells containing numbers are "text" formatted, one may get NULL values into an integer column of the database).

    Solution:

    1. Create a new excel sheet with the name of the columns in the first row
    2. Format the columns as text
    3. Paste the rows without format (use CVS format or copy/paste in Notepad to get only text)

    Note that formatting the columns on an existing Excel sheet is not enough.

提交回复
热议问题