LZ:你Content应该不止含有 http://192.168.1.110/ 这个吧
如果你只想更新含有http://192.168.1.110/ 这个的话,Try[注意:下面语句只能更新<8000字符内的Content]Declare @T Table(id int,Content ntext)
Insert @T Select 1,'http://192.168.1.110/掌骨额http://192.168.1.110/阳升的地方http://192.168.1.110/永点http://192.168.1.110/ '
Union All Select 2,'李四http://192.168.1.110/张三http://192.168.1.110/阳升的地方'
--更新
Update @T Set Content=Replace(Cast(Content As Varchar(8000)),'http://192.168.1.110/','web')
--查询更新后的结果
Select * From @T---结果
/*
id Content
----------- ---------------------------------
1 web掌骨额web阳升的地方web永点web
2 李四web张三web阳升的地方(所影响的行数为 2 行)
*/
如果你只想更新含有http://192.168.1.110/ 这个的话,Try[注意:下面语句只能更新<8000字符内的Content]Declare @T Table(id int,Content ntext)
Insert @T Select 1,'http://192.168.1.110/掌骨额http://192.168.1.110/阳升的地方http://192.168.1.110/永点http://192.168.1.110/ '
Union All Select 2,'李四http://192.168.1.110/张三http://192.168.1.110/阳升的地方'
--更新
Update @T Set Content=Replace(Cast(Content As Varchar(8000)),'http://192.168.1.110/','web')
--查询更新后的结果
Select * From @T---结果
/*
id Content
----------- ---------------------------------
1 web掌骨额web阳升的地方web永点web
2 李四web张三web阳升的地方(所影响的行数为 2 行)
*/
Try[注意:下面语句只能更新 <8000字符内的Content] Declare @T Table(id int,Content ntext)
Insert @T Select 1,'http://192.168.1.110/掌骨额http://192.168.1.110/阳升的地方http://192.168.1.110/永点http://192.168.1.110/ '
Union All Select 2,'李四http://192.168.1.1/张三http://192.168.1.100/阳升的地方' --注意这里有http://192.168.1.1/等地址---更新
While Exists(Select 1 From @T Where CharIndex('http://',Content)>0)
Update @T
Set Content=Stuff(Cast(Content As Varchar(8000)),CharIndex('http://',Content),CharIndex('/',Content,CharIndex('//',Content)+2)-CharIndex('http://',Content)+1,'web')
Where CharIndex('http://',Content)>0--查询更新后的结果
Select * From @T---结果
/*
id Content
----------- -------------------------------
1 web掌骨额web阳升的地方web永点web
2 李四web张三web阳升的地方(所影响的行数为 2 行)
*/
DECLARE @insert_offset int,@delete_length int
DECLARE @newstr varchar(50)set @delete_length = len('http://192.168.1.110/')
set @newstr = 'web'select @insert_offset = patindex('%http://192.168.1.110/%',str)-1 from a where id=1DECLARE @ptrval binary(16)
SELECT @ptrval = TEXTPTR(str) FROM a where id=1
UPDATETEXT a.str @ptrval @insert_offset @delete_length @newstr
这个不限制字段长度的,但是只更新第一次出现的,可以自己修改一下