Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 separate out

Author  Topic 

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2013-10-18 : 03:07:35
I have this column:
<DESC v="123456"/><TRACE v="456789"/><BATCH v="123"/><TERM v="654321"/>

how can i separate out

Desc Trace Batch Term
123456 456789 123 654987

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-18 : 03:21:48
Your XML is not well formed (may be you didnt post full part)
Anyways if its just like above you can do like


SELECT m.n.value('(./DESC/@v)[1]','int') AS [Desc],
m.n.value('(./TRACE/@v)[1]','int') AS [Trace],
m.n.value('(./BATCH/@v)[1]','int') AS [Batch],
m.n.value('(./TERM/@v)[1]','int') AS [Term]
FROM (SELECT CAST('<Root>' + Column + '</Root>' AS xml) AS x FROM table)t
CROSS APPLY x.nodes('/Root')m(n)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -