12

您好我正在尝试将数据从 excel 文件导入(xls)到新文件中,SQL table所以我Import and Export data 32/bit用来实现这一点。当我加载 excel 文件时,它会自动检测列的数据类型。例如,带有电话号码的列作为新表的数据类型,float而在 Excel 中,当我尝试将其更改为 Double(15)floatnvarchar

我明白了:

找到 2 个未知的列类型转换 您已选择跳过 1 个可能丢失的列转换 您已选择跳过 3 个安全的列转换

而且我不允许继续出口。

尝试导入时有什么方法可以更改数据类型?

感谢您的时间。

这些数据在 excel 中设置为text数据类型 来自 excel 中某一列的示例数据:

5859031783

5851130582

8811014190

这就是我得到的:

在此处输入图像描述

4

2 回答 2

26

Select the Column in your Excel sheet and change the data type to text

enter image description here

Then go to your sql server open import-export wizard and do all the steps of select source data and bla bla when you get to the point of Mapping Column, it will select Float data type by default, You will have to change it to NVARCHAR(N) in my test I changed it to NVARCHAR(400), it gave me a warning that I might lose some data as I am converting data from 1 datatyep to another.

enter image description here

When you get to the Data Type Mapping page make sure you select Convert checkbox. and stop the process of failure of as appropriate.

enter image description here

Going through all these steps finally got my data in the destination table with the same Warning that I have converted some data n bla bla after all microsoft worries too much :)

enter image description here

Finally Data in Sql-Server Table

╔═══════╦════════════╦═════════╦════════════════╦══════════════╗
║ Name  ║    City    ║ Country ║     Phone      ║ Float_Column ║
╠═══════╬════════════╬═════════╬════════════════╬══════════════╣
║ Shaun ║ London     ║ UK      ║ 04454165161665 ║   5859031783 ║
║ Mark  ║ Newyork    ║ USA     ║ 16846814618165 ║   8811014190 ║
║ Mike  ║ Manchester ║ UK      ║ 04468151651651 ║   5851130582 ║
╚═══════╩════════════╩═════════╩════════════════╩══════════════╝
于 2014-01-04T18:49:07.307 回答
1

我非常不喜欢 SQL Server 导入/导出向导。

不是一个直接的答案,但我发现使用向导的最佳猜测然后在 SQL Server 中修复表规范并不那么令人沮丧。

于 2021-04-16T15:44:39.770 回答