本文介绍了在sql server中使用xml数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! Hi Team, 我使用xml以下来检索数据 声明@exp XML set @ exp = N'< SpItem > < SPId > 1 < / SPId > < NName > ab < / NName > < Expr > < Oprt > < / Oprt > < Nr > 10 < / Nr > < Oprt > + < / Oprt > < 数据 > < 输入 > Mc < ; /类型 > < ID > 10 < ; / Id > < 值 > Mc Value < / Value > < / Data > < Oprt > + < / Oprt > < 数据 > < 类型 > DataElement < / Type > < Id > 10 < / Id > < 值 > Mc Value < / Value > < / Data > < Oprt > * < / Oprt > < SPItem > < SPId > < / SPId > < NName > 我的SPad < / NName > < Expr > < Oprt > < / Oprt > < 数据 > < 输入 > 指标< /类型 > < 编号 > 10 < / Id > < 值 > Mc Value < / Value > < / Data > < / Expr > < / SPItem > < / Expr > < / SpItem > ' 我用以下查询来检索 选择 col.value(' (Oprt / text())[1]',' varchar(50) '), col.value(' (text())[1]',' varchar(50)') 来自 @exp .nodes(' // Expr') as 标签(col) cross apply col.nodes(' 数据) as dtype(dt) 可以帮助我从xml中检索所有数据。在此先感谢。解决方案 SPId NName Oprt Nr Type内部SPId 1 ab 10 1 ab + 10 DataElement 1 ab + 10 Mc 1 ab * 1 ab + 10 Metric 2 这是预期的输出 Hi Team,I Am using below xml to retrieve datadeclare @exp XMLset @exp=N'<SpItem> <SPId>1</SPId> <NName>ab</NName> <Expr> <Oprt> </Oprt> <Nr>10</Nr> <Oprt>+</Oprt> <Data> <Type>Mc</Type> <Id>10</Id> <Value>Mc Value</Value> </Data> <Oprt>+</Oprt> <Data> <Type>DataElement</Type> <Id>10</Id> <Value>Mc Value</Value> </Data> <Oprt>*</Oprt> <SPItem> <SPId></SPId> <NName>My SPad</NName> <Expr> <Oprt> </Oprt> <Data> <Type>Metric</Type> <Id>10</Id> <Value>Mc Value</Value> </Data> </Expr> </SPItem> </Expr></SpItem>'and i used below query to retrieveselectcol.value('(Oprt/text())[1]','varchar(50)'),col.value('(text())[1]','varchar(50)') from @exp.nodes('//Expr') as tab(col) cross apply col.nodes('Data') as dtype(dt)can any one help me to retrieve all the data from xml. Thanks in advance. 解决方案 SPIdNNameOprtNrTypeInner SPId1 ab 101 ab+ 10 DataElement1 ab+ 10 Mc1 ab*1 ab+ 10 Metric 2Here is the expected out put 这篇关于在sql server中使用xml数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-31 04:47