XML

  • CREATE TABLE [dbo].[Abc](

    [sid] [int] NULL,

    [sname] [varchar](20) NULL

    ) ON [PRIMARY]

    GO

    SET ANSI_PADDING OFF

    GO

    INSERT INTO [Abc]

    ([sid]

    ,[sname])

    VALUES(1,'xx')

    INSERT INTO [Abc]

    ([sid]

    ,[sname])

    VALUES(2,'yy')

    INSERT INTO [Abc]

    ([sid]

    ,[sname])

    VALUES(3,'zz')

    INSERT INTO [Abc]

    ([sid]

    ,[sname])

    VALUES(3,'zz & vv')

    SELECT

    DISTINCT ',' + [sname]

    FROM [Abc]

    ORDER BY ',' + [sname]

    FOR

    XML PATH ('')

    output :

    for "zz & vv" its displaying as zz amp; vv

    I need output as 'zz & vv' .Can u please help me how to get it. since I need to compare this value..There might several Special characters like this in the column .

  • /* Sample data */

    CREATE TABLE [dbo].[Abc] ([sid] [int] NULL, [sname] [varchar](20) NULL) ON [PRIMARY];

    INSERT INTO [Abc] ([sid], [sname])

    VALUES (1, 'xx');

    INSERT INTO [Abc] ([sid], [sname])

    VALUES (2, 'yy');

    INSERT INTO [Abc] ([sid], [sname])

    VALUES (3, 'zz');

    INSERT INTO [Abc] ([sid], [sname])

    VALUES (3, 'zz & vv');

    /* Actual Query */

    SELECT STUFF((SELECT ',' + [sname]

    FROM [Abc]

    ORDER BY [sname]

    FOR XML PATH(''), TYPE).value('.', 'varchar(max)'),1,1,'');

    /* Results

    ------------------

    xx,yy,zz,zz & vv

    */


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Thank u ..

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

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