October 7, 2009 at 8:04 pm
Hi all!
I have a varchar(max) field where I store HTML documents. I'm planning to add a custom tag to all the documents for later use to update the "CompanyName".
I plan to put some tags in the documents where the company name will be, somthing like: "<g:cn> The ComplanyName </g:cn>"
Later when I need to use the documents for an other company, I can replace the text between the tags.
So my question is : are there a SQL function that can replace text inside a such tags? I have spent several hours searching the net, but I could find nothing useful.
Atle
October 8, 2009 at 8:14 am
This should get you started:
Declare @html varchar(max);
Set @html = '<g:cn> The ComplanyName </g:cn>';
Select
@html,
Stuff(@html, Patindex('%<g:cn>%', @html) + 6, Patindex('%</g:cn>%', @html) - (Patindex('%<g:cn>%', @html) + 6), 'New CompanyName')
PatIndex finds the start location of a specific pattern within a string. Stuff replaces any characters at the given start position fro the given length. For more details look up the functions in BOL.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
October 8, 2009 at 12:03 pm
Fanstatic!
Thank you Jack, I didn't think about solving it that easy. I will use this.
Regards
Atle
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply