简体   繁体   English

循环遍历临时表,比较和设置值

[英]Looping through a temporary table, comparing and setting values

I am looking for a way to be able to go through a CSV file or add the data of the CSV to a temporary table (I know how to do this part) and then compare the temporary table on one column with my permanent table and on the row it matches, set another column to a value within the temporary table. 我正在寻找一种能够通过CSV文件或将CSV的数据添加到临时表(我知道如何执行此部分)然后将一列上的临时表与我的永久表进行比较的方法它匹配的行,将另一列设置为临时表中的值。

if(Old_Url = Old Url)
{
  new_url = new_url
}

That's a bad code example of what I want to do as I have no idea how to show this in SQL 这是我想要做的一个糟糕的代码示例,因为我不知道如何在SQL中显示它

You don't loop (generally) in SQL - you write a query that applies to entire sets of rows. 您不会(通常)在SQL中循环 - 您编写一个适用于整个行的查询。

It looks like you want some form of update: 看起来你想要某种形式的更新:

UPDATE p
SET new_url = t.new_url
FROM PermanentTable p
INNER JOIN TemporaryTable t
ON p.old_url = t.old_url

(Although you should be cautious if TemporaryTable might contain multiple rows with the same old_url value and different new_url values - it's not well defined which values will be applied to any matching rows in PermanentTable ) (尽管如果TemporaryTable可能包含多个具有相同old_url值和不同new_url值的行,则应该保持谨慎 - 但没有明确定义哪些值将应用于PermanentTable任何匹配行)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM