我将如何使用 excel 生成大型更新 sql 语句?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21177669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 00:46:29  来源:igfitidea点击:

How would I use excel to generate a large update sql statement?

sqlexcel

提问by ShaunK

I know there's a way to have insert statements within excel. Is there one for update? so far I've managed to come up with my update statement in SQL, but I have 6000 rows to update:

我知道有一种方法可以在 excel 中插入语句。有更新的吗?到目前为止,我已经设法在 SQL 中提出了我的更新语句,但我有 6000 行要更新:

= "Update table Set name = " & A1 & " Where namefk = " & E2 & ""

= "更新表集名称 = " & A1 & " where namefk = " & E2 & ""

Basically, I want the name and namefk to be populated with fields in my excel..but I can't seem to get it right. Any help will be appreciated.

基本上,我希望 name 和 namefk 在我的 excel 中填充字段..但我似乎无法正确。任何帮助将不胜感激。

回答by Hasya

= "update table set name = '" & B1 & "' where namefk = '" & A1 & "'"

where column A1 has name fk & B1 have name You can drag the formula to achieve query to update thousands of records :) You can look into the link with the Example excelHope it helps

其中 A1 列的名称为 fk & B1 的名称您可以拖动公式来实现查询以更新数千条记录:) 您可以查看示例 excel的链接 希望它有所 帮助

回答by Pankti Shah

=CONCATENATE("update Site set SiteName='",D13,"' where Place='",A13,"' and Code='",B13,"'")

=CONCATENATE("update Site set SiteName='",D13,"' where Place='",A13,"' and Code='",B13,"'")

As per above we can make update query dynamically and if we make for one row after that we need to drag down, so automatically it will take column values.

如上所述,我们可以动态进行更新查询,如果我们在此之后创建一行,我们需要向下拖动,因此它会自动获取列值。