SQL 用新值替换旧值 [英] SQL replace old values with new ones

查看:48
本文介绍了SQL 用新值替换旧值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 tbl.Products 的表,其中有一列名为 articlenumber 并且充满了诸如 s401 之类的数字s402

I have a table named tbl.Products, which has a column named articlenumber and is full of numbers like s401, s402, etc.

我生成了一个包含新文章编号的列表,它将替换旧的文章编号:

I generated a list with new article numbers which will replace the old ones:

s401  I00010  
s402  I00020  
s403  I00030  
s403  I00040  
...  

我有一个查询,我希望它能解决问题,但不知何故它什么也没做.

I have a query from which I hoped that it would work out, but somehow it does nothing.

(当然我已经将其他值嵌套到查询中)

(of course I have nested the other values into the query)

SELECT REPLACE('articlenumber','s401','I00010') FROM tbl.Products

如何在这样的列中获取用新值替换旧值的查询?

How do I get a query which replaces old values with new ones in a column like this?

推荐答案

你只是选择了新替换的值,而不是对它们做任何事情......这是使用替换时的一个很好的主意,总是先选择再检查一下你会得到预期的结果:)

You are just selecting the newly replaced values and not doing anything with them... thats a very good idea when using replace, always select first to double check that you will get the expected result :)

更新代码 -

Update  tbl.Products
Set articlenumber = replace(articlenumber, 's401', 'I00010') 

这篇关于SQL 用新值替换旧值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆