Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

XML in SQL Server Expand / Collapse
Author
Message
Posted Saturday, October 13, 2012 2:14 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, May 08, 2013 4:17 AM
Points: 3, Visits: 42
I have a table like below.

value xml_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?
Post #1372406
Posted Monday, October 15, 2012 1:48 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, April 08, 2014 6:13 AM
Points: 1,694, Visits: 19,550
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)



____________________________________________________

How to get the best help on a forum

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

Never approach a goat from the front, a horse from the rear, or a fool from any direction.
Post #1372585
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse