Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Strip XML tags, add an space between results

$
0
0

I found a function on the internet which works really fast and doesn't require an UDF or CLR that removes the tags in an XML field.  The problem I have with the function I've found is that it concatinates the values with no spaces or characters in between. I'm not very good with XML and especially not good with XML and SQL server, so can some-one help me out (I have literly tried for hours on my own) adjusting this so that it out puts the text with an space between values?

ALTER function [dbo].[StripTags]( @text varchar(max) ) returns varchar(max) as
begin
    declare @textXML xml
    declare @result varchar(max)
    set @textXML = REPLACE( @text, '&', '' );
    with doc(contents) as
    (
        select chunks.chunk.query('.') from @textXML.nodes('/') as chunks(chunk)
    )
    select @result = contents.value('.', 'varchar(max)') from doc
    return @result
end

GO



George P Botuwell, Programmer


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>