SQLServer如何批量替换某一列中的某个字符串

我们在开发系统的时候经常会碰到类似如下这样的情况:比如我有一张数据表

假如我现在要把红圈中这列的的http://www.mylanqiu.com/ 这个字符串批量替换成mylanqiu 这个字符串,这个要怎么实现?其实这个很简单,只要使用SQL的Replace函数就可以了,代码如下:

 update [HelloCode].[dbo].[AD]
  set [Contents]=REPLACE([Contents],'http://www.mylanqiu.com/','mylanqiu')
  where  Contents like '%www.mylanqiu.com%'

Replace函数的用法:

Replace(数据库的列名,'要被替换掉的字符串','要用于替换的字符串')

posted @ 2018-09-27 15:55  mylanqiu  阅读(22629)  评论(1编辑  收藏  举报