XML in SQL Server

  • I have a table like below.

    valuexml_1

    1+2<root><s>1</s><s>2</s></root>

    3+4<root><s>3</s><s>4</s></root>

    I want to get the value like,

    1+2 1

    1+2 2

    3+4 3

    3+4 4

    Can you guys please help me urgently?

  • DECLARE @t TABLE(value VARCHAR(10),xml_1 XML)

    INSERT INTO @T(value,xml_1)

    VALUES('1+2','<root><s>1</s><s>2</s></root>'),

    ('3+4','<root><s>3</s><s>4</s></root>')

    SELECT value,x.r.value('.','INT') AS s

    FROM @t

    CROSS APPLY xml_1.nodes('/root/s') AS x(r)

    ____________________________________________________

    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

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

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