sql - alternatives to REPLACE on a text or ntext datatype -
i need update/replace data in datatable.column. table has field named content. i'm using replace function. since column datatype ntext, sql server doesn't allow me use replace function.
i can't change datatype because database 3rd party software table. changing datatype cause application fail.
update [cms_db_test].[dbo].[cms_htmltext] set content = replace(content,'abc','def') content '%abc%' i receive error:
msg 8116, level 16, state 1, line 1 argument data type ntext invalid argument 1 of replace function.
- can fix t-sql? have example how read , loop?
- since onetime conversion, maybe can change type i'm afraid i'm messing data.
there primary key field: name: id - integer - it's identity.... need think too. maybe set identity n temporary.
please advise on how achieve replace function?
approx. 3000 statements need updated new solution.
if data won't overflow 4000 characters and you're on sql server 2000 or compatibility level of 8 or sql server 2000:
update [cms_db_test].[dbo].[cms_htmltext] set content = cast(replace(cast(content nvarchar(4000)),'abc','def') ntext) content '%abc%' for sql server 2005+:
update [cms_db_test].[dbo].[cms_htmltext] set content = cast(replace(cast(content nvarchar(max)),'abc','def') ntext) content '%abc%'
Comments
Post a Comment