STUFF function issue with HTML tag

  • Hey,

    I have the following query that supposes to merge multiple result in a single one and put it into a temporary table:

    SELECT DISTINCT [AlphaExtension],

    STUFF((SELECT A.[NoteText] + '< BR />' FROM #temp A

    WHERE A.[AlphaExtension]=B.[AlphaExtension]

    FOR XML PATH('')),1,1,'') As [NoteText]

    FROM #temp B

    GROUP BY [AlphaExtension], [NoteText]

    It is working fine unless by a simple detail. If you look at the second line of the query you will see that I am stuffing together a < BR /> tag (break line) because the contents of the field is going to be spitted directly to the screen and I want that the multiple results be displayed in different lines.

    OK, the issue is that it is stuffing & lt ; BR / & gt ; instead < BR /> and therefore the browser is displaying the tag instead to break a line.

    Any idea to fix it?

    PS: I added some blank spaces in the HTML tag to avoid forum engine process it as a real tag.

  • SELECT DISTINCT [AlphaExtension],

    STUFF((SELECT A.[NoteText] + '< BR />' AS "text()"

    FROM #temp A

    WHERE A.[AlphaExtension]=B.[AlphaExtension]

    FOR XML PATH(''),TYPE).value('./text()[1]','NVARCHAR(MAX)'),1,1,'') As [NoteText]

    FROM #temp B

    GROUP BY [AlphaExtension], [NoteText]

    ____________________________________________________

    Deja View - The strange feeling that somewhere, sometime you've optimised this query before

    How to get the best help on a forum

    http://www.sqlservercentral.com/articles/Best+Practices/61537
  • Mark,

    It was simply absolutelly perfect!

    Thank you very much, buddy!

    🙂

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply