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

前端 未结 6 1063
暗喜
暗喜 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:25

    A workaround to consider in a pinch:

    1. save a copy of the excel file, modify the column to format type 'text'
    2. copy the column values and paste to a text editor, save the file (call it tmp.txt).
    3. modify the data in the text file to start and end with a character so that the SQL Server import mechanism will recognize as text. If you have a fancy editor, use included tools. I use awk in cygwin on my windows laptop. For example, I start end end the column value with a single quote, like "$ awk '{print "\x27"$1"\x27"}' ./tmp.txt > ./tmp2.txt"
    4. copy and paste the data from tmp2.txt over top of the necessary column in the excel file, and save the excel file
    5. run the sql server import for your modified excel file... be sure to double check the data type chosen by the importer is not numeric... if it is, repeat the above steps with a different set of characters

    The data in the database will have the quotes once the import is done... you can update the data later on to remove the quotes, or use the "replace" function in your read query, such as "replace([dbo].[MyTable].[MyColumn], '''', '')"

提交回复
热议问题