dstjohnjr
asked on
Search and Replace script for Ntext field
I need a sql query / script that will search and replace a text string in 1 of the tables & fields of my database. I know the DB, Table and Field name. I just need to search and replace %SearchString% with %ReplaceString% (for example).
TIA!
TIA!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, the first one by angellll did not work. It renders this error:
Msg 8116, Level 16, State 1, Line 1
Argument data type ntext is invalid for argument 1 of replace function.
Then, trying Brandons. Better luck, but still only replaced two occurences of my string... when I know others exist. Odd. Hmmm.... Any ideas?
Msg 8116, Level 16, State 1, Line 1
Argument data type ntext is invalid for argument 1 of replace function.
Then, trying Brandons. Better luck, but still only replaced two occurences of my string... when I know others exist. Odd. Hmmm.... Any ideas?
I indeed overlooked the NTEXT part, sorry.
now, with SQL 2008, you should NOT use NTEXT anymore, but NVARCHAR(MAX), and the UPDATE will work correctly.
now, with SQL 2008, you should NOT use NTEXT anymore, but NVARCHAR(MAX), and the UPDATE will work correctly.
No because the replace is a replace all, unless your db or server is set for case sensitive sort order.
If you are using case sensitive SQL, then it won't replace 'ABC' if you are searching for 'abc'.
ASKER
I figured it out! Here was my final code. I was using an actual double quote character when it actually resided in my field as "
UPDATE [VERIATECH_SHARED_DNN].[db o].[VDNN_H tmlText]
SET [DesktopHtml] = REPLACE(cast([DesktopHtml] as nvarchar(max)), 'src="/Portals/0/', 'src="/Portals/VeriaT ech/')
WHERE [DesktopHtml] LIKE '%src="/Portals/0/%'
Thanks for the assistance!
UPDATE [VERIATECH_SHARED_DNN].[db
SET [DesktopHtml] = REPLACE(cast([DesktopHtml]
WHERE [DesktopHtml] LIKE '%src="/Portals/0/%'
Thanks for the assistance!
ASKER
and for the record, this is in the latest version of DotNetNuke - freshly installed, version 4.9.0 I believe. Was migrating a site from one server using SQL Server 2005 to our new server which uses SQL Server 2008. Had some pathing issues I had to fix and didn't want to go through them one by one.
ASKER
Thank you Brandon! Great solution provided once I figured out the deal with the quote char (which actually resided in my db as ").
Open in new window