比较期间使用的 SQL 替换 [英] SQL Replace used during a compare
问题描述
我目前运行此查询:
UPDATE table1
SET column1 = table2.columnA
FROM table2
WHERE column2 = table2.columnA
AND column3 = table2.columnC
是的,有重复的列,抱歉.
Yes there is a duplicate column, sorry.
当我将 column2
与 table2.columnA
交叉引用时,有机会获得 NULL
因为 column2
<强>不包含/
,其中table2.columnA
可能包含/
When I cross reference column2
with table2.columnA
there is a chance to get NULL
because column2
DOES NOT contain /
where as table2.columnA
may contain /
我不想改变table2.columnA
中的数据
据我所知,我可以运行此查询来REPLACE
字符.
It is my understanding that I can run this query to REPLACE
the characters.
SELECT REPLACE ([table2.columnA],'/','-')
FROM table2
这不会对 table2
造成永久性更改是必要的,所以我想确保我做对了,或者看看是否有更好的方法.
It is necessary that this does not make a permanent change to table2
so I want to make sure that I am getting this right or to see if there is a better way.
现在我想合并这两个查询,但不确定如何合并.
Now I want to combine the two queries but am unsure how.
UPDATE table1
SET column1 = table2.columnA
FROM table2
WHERE column2 = (SELECT REPLACE([table2.columnA],'/','-')table2.columnA)
FROM table2
AND column3 = table2.columnC
感谢您的帮助!
推荐答案
类似的东西
UPDATE table1
SET column1 = table2.columnA
FROM table1
inner join table2
on table1.column2 = REPLACE([table2.columnA],'/','-')
and table1.column3 = table2.columnC
这篇关于比较期间使用的 SQL 替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!