none
Bug In Xml Path with "&" RRS feed

  • Question

  • hi

    i found out that when i use a charachter "&" in xml path ,result falling into wrong way and some irrelative words added to it.

    for example:

    SELECT ' Hi dady & How are you'  FOR XML PATH('')

    result:

     Hi dady & How are you

    the irrelative words: "amp;"

    i searched that there is no limitation wildcard in xml path so i posted here to know what is this problem exactly?is it really a bug?or not?

    thanks a lot for any idea!

    Saturday, July 23, 2016 11:15 AM

Answers

  • Hi Kodamins,
    hope to helps:
    CREATE TABLE dbo.x(y NVARCHAR(255));
    
    
    INSERT dbo.x SELECT 'Sports & Recreation'
        UNION ALL SELECT 'x >= y'
        UNION ALL SELECT 'blat'
        UNION ALL SELECT '<hooah>';
    
    
    -- bad:
     SELECT STUFF((SELECT ',' + y
      FROM dbo.x FOR XML PATH('')), 1, 1, '');
    
    
    -- good:
     SELECT STUFF((SELECT ',' + y
      FROM dbo.x FOR XML PATH, TYPE).value('.[1]',
      'nvarchar(max)'), 1, 1, '');
    
    
     GO
      DROP TABLE dbo.x;



    Saturday, July 23, 2016 2:22 PM