我有一个包含以下数据的Excel文件:

我需要将此数据以列表形式插入到SQL Server表中。
示例:

因此,我必须转换Excel中的表格格式,并且只有3列:
degreeant, positionant, amount有什么线索吗?
发布于 2018-01-14 07:13:52
您可以使用自己喜欢的工具(SSIS?)将数据导入SQL Server。转换为与excel文件具有相同结构的临时表。然后,使用查询将数据附加到目标表:
insert into TargetTable(degreeant, positionant, Amount)
SELECT degreeant, 0 as Positionant, Positionant_0 from StagingTable
union all
SELECT degreeant, 1 as Positionant, Positionant_1 from StagingTable
union all
SELECT degreeant, 2 as Positionant, Positionant_2 from StagingTable
{...}发布于 2018-01-14 07:19:37
将excel数据转换为制表符分隔的文件。然后将每一行放入一个数组中。在那之后,取必要的数组元素编号。并编写要插入的数据库查询。
file = open(“tsf”, “r”) //tab seperated file is read
//open db connection here
for line in file:
array = line.split("\t")
//insert necessary elements of b with query here
// eg. insert into table values(array[0], array[2], array[4])
pass
//close db connection 发布于 2018-01-14 07:56:11
我找到了一种更好的方法,用带有Unpivot表的Excel来完成这项工作

选择要取消透视的所有列

单击Unpivot按钮

瞧!

https://stackoverflow.com/questions/48245109
复制相似问题