0

我有一个包含以下字段的数据库产品 | 资产 | 序列号 | 等等..这些字段是从 Excel 表中导入的。我现在需要从 excel 表中将一个附加字段导入数据库,首先我花了几个小时来格式化表,我不想再这样做了。

还有一个名为 productnumber 的附加字段。

说我只是将所有的 excel 数据乱七八糟地导入到我的 sql db 上的另一个表中

我可以做什么样的功能/查询/任何事情

foreach( item in table1) {
    if(item.serial = table2.serial) {
        item.productnumber = table2.productnumber 
    }
}

我在脑海中看到数据表,但我不确定如何让每一行在继续之前检查整个表?

多谢你们

编辑:好的,所以我现在有两张桌子

表 1 和表 2

表 1 ID | 姓名 | 序列号 | 标签 | 资产编号 | 等等... 表 2 序列号 | 标签 | 资产编号

我现在需要将所有数据从 table2.tag 复制到 table1.tag 并匹配assetNo

谢谢

4

1 回答 1

0

最好的办法是直接将excel表导入sql server数据库,然后在你原来的表中添加一列,进行更新操作。

假设您的原始表是table1并且serial是主键。将数据从 excel 导入到新表中说table2。更改table1并添加必要的字段 ( productnumber)。

执行以下更新查询

update table2 set table2.productnumber =table1.productnumber
from table2 inner join table1 on table2.serial = table1.serial
于 2013-11-05T16:39:05.567 回答