Missy
2014-11-17 20:30:00 UTC
I am little bit struggling to get the my sql function below, to execute the correct output:
ALTER FUNCTION [dbo].[ReplaceTags](@XML VARCHAR(MAX))
RETURNS VARCHAR(MAX)
AS
BEGIN
SELECT @XML = REPLACE(@XML,[Name],'<a href="<a href="pagename.aspx?tag='+[name]+'">'+[name]+'</a>')
FROM [dbo].[database_tags]
where UploadDate >= '2014-09-01'
RETURN @XML
END
I am trying to replace names found in 'xml' fieldname as hyperlinks, by matching with the names in database_tags.
for example, the following input is passed into the UDF:
<Body><p align="justify">One is a 1m block of AIREM 2006-1X 2A3, which has never appeared on SMO.<p></Body>
and the function outputs the following (which is incorrect).
One is a &#163;1m block of <a href="<a href="pagename.aspx?tag=<a href="<a href="pagename.aspx?tag=<a href="<a href="pagename.aspx?tag=<a href="<a href="pagename.aspx?tag=<a href="<a href="pagename.aspx?tag=AIREM 2006-1X 2A3">AIREM 2006-1X 2A3</a>"><a href="<a href="pagename.aspx?tag=AIREM 2006-1X 2A3">AIREM 2006-1X 2A3</a></a>"><a href="<a href="pagename.aspx?tag=<a href="<a href="pagename.aspx?tag=AIREM 2006-1X 2A3">AIREM 2006-1X 2A3</a>"><a href="<a href="pagename.aspx?tag=AIREM 2006-1X 2A3">AIREM 2006-1X 2A3</a>
I believe the issue, is in function's loop (select statement).
Is there a way, I can improve the UDF, so, as soon as it finds a matching name from database_tags table, it exit the loop.
Is there an example I could look into, which can help me further solve this issue.
Many thanks
ALTER FUNCTION [dbo].[ReplaceTags](@XML VARCHAR(MAX))
RETURNS VARCHAR(MAX)
AS
BEGIN
SELECT @XML = REPLACE(@XML,[Name],'<a href="<a href="pagename.aspx?tag='+[name]+'">'+[name]+'</a>')
FROM [dbo].[database_tags]
where UploadDate >= '2014-09-01'
RETURN @XML
END
I am trying to replace names found in 'xml' fieldname as hyperlinks, by matching with the names in database_tags.
for example, the following input is passed into the UDF:
<Body><p align="justify">One is a 1m block of AIREM 2006-1X 2A3, which has never appeared on SMO.<p></Body>
and the function outputs the following (which is incorrect).
One is a &#163;1m block of <a href="<a href="pagename.aspx?tag=<a href="<a href="pagename.aspx?tag=<a href="<a href="pagename.aspx?tag=<a href="<a href="pagename.aspx?tag=<a href="<a href="pagename.aspx?tag=AIREM 2006-1X 2A3">AIREM 2006-1X 2A3</a>"><a href="<a href="pagename.aspx?tag=AIREM 2006-1X 2A3">AIREM 2006-1X 2A3</a></a>"><a href="<a href="pagename.aspx?tag=<a href="<a href="pagename.aspx?tag=AIREM 2006-1X 2A3">AIREM 2006-1X 2A3</a>"><a href="<a href="pagename.aspx?tag=AIREM 2006-1X 2A3">AIREM 2006-1X 2A3</a>
I believe the issue, is in function's loop (select statement).
Is there a way, I can improve the UDF, so, as soon as it finds a matching name from database_tags table, it exit the loop.
Is there an example I could look into, which can help me further solve this issue.
Many thanks