SQL Server 用通配符替换命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13253259/
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 11:59:02  来源:igfitidea点击:

SQL Server Replace Command with WIldcard

sqlsql-serversql-server-2008

提问by CaptHowdy

I am in need of some help. Thanks to fellow user davids, I was able to get certain things working within SQL Server and am in need of some more help. Here is what I am trying to do:

我需要一些帮助。感谢其他用户 davids,我能够在 SQL Server 中运行某些东西,并且需要更多帮助。这是我想要做的:

UPDATE Table1 SET keyfield=(REPLACE(REPLACE(Column1,'http://*/folder/',''),'.avi',''))
UPDATE Table2 SET keyfield=(REPLACE(REPLACE(Column2,'http://server2/folder/',''),'.mpg',''))

Can anyone help me out or point me in the right direction to get the wildcard to work? This particular column, the * is an IP Address and it will change all the time. Granted I will know the IP's ahead of time and can probably do it one by one, but I would prefer to have it automatically replace. Thanks in advance!

任何人都可以帮助我或指出正确的方向以使通配符起作用吗?这个特定的列,* 是一个 IP 地址,它会一直改变。当然,我会提前知道 IP 并且可能可以一一完成,但我更愿意让它自动替换。提前致谢!

回答by Klas Lindb?ck

You should look into regular expressions.

你应该研究正则表达式。

My google karma found this article in MSDN Magazine.

我的 google karma在 MSDN 杂志中找到了这篇文章

Edit:

编辑:

See also: Perform regex (replace) in an SQL query

另请参阅: 在 SQL 查询中执行正则表达式(替换)