如何从SQL Server中的xml数据中获取带有条件的子元素和属性值?

穆萨克希尔·赛义德(Musakkhir Sayyed)

如何在SQL Server中获取带有条件的子值及其属性值?如何获得

<CheckoutAttribute ID="9">
<CheckoutAttributeValue><Value>26</Value></CheckoutAttributeValue> 
CheckoutAttributeID CheckoutAttributeValue 
        9 26

来自以下xml数据。

<Attributes>
<CheckoutAttribute ID="4">
<CheckoutAttributeValue><Value>18</Value></CheckoutAttributeValue>
</CheckoutAttribute>
<CheckoutAttribute ID="6">
<CheckoutAttributeValue><Value>22</Value></CheckoutAttributeValue>
<CheckoutAttributeValue><Value>23</Value></CheckoutAttributeValue>
</CheckoutAttribute>
<CheckoutAttribute ID="9">
<CheckoutAttributeValue><Value>26</Value></CheckoutAttributeValue>
<CheckoutAttributeValue><Value>27</Value></CheckoutAttributeValue>
</CheckoutAttribute>
<CheckoutAttribute ID="1">
<CheckoutAttributeValue><Value>1</Value></CheckoutAttributeValue>
</CheckoutAttribute>
</Attributes>
曼德森
CREATE TABLE #tempTable ( id INT IDENTITY(1,1), xmlDataTest xml)
INSERT INTO #TempTable ( xmlDataTest)
VALUES ('<Attributes>
<CheckoutAttribute ID="4">
<CheckoutAttributeValue><Value>18</Value></CheckoutAttributeValue>
</CheckoutAttribute>
<CheckoutAttribute ID="6">
<CheckoutAttributeValue><Value>22</Value></CheckoutAttributeValue>
<CheckoutAttributeValue><Value>23</Value></CheckoutAttributeValue>
</CheckoutAttribute>
<CheckoutAttribute ID="9">
<CheckoutAttributeValue><Value>26</Value></CheckoutAttributeValue>
<CheckoutAttributeValue><Value>27</Value></CheckoutAttributeValue>
</CheckoutAttribute>
<CheckoutAttribute ID="1">
<CheckoutAttributeValue><Value>1</Value></CheckoutAttributeValue>
</CheckoutAttribute>
</Attributes>')

SELECT r.value('@ID','int') AS CheckoutAttributeID
        , r.query('data(CheckoutAttributeValue/Value)[1]') AS CheckoutAttributeValue
FROM #tempTable
CROSS APPLY xmlDataTest.nodes('/Attributes/CheckoutAttribute') AS x(r)
WHERE
r.value('@ID','int') = 9 

DROP TABLE #tempTable

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

SQL Server中带有条件的案例陈述

SQL中带有条件“和”的嵌套If语句

如何在数组中显示/获取带有条件的数据?

如何在 Sql Server 中添加带有条件的默认约束?

从MS SQL Server 2012中的另一个表获取带有条件的最新行

带有条件语句的SAS SQL中的子查询

如何在 MongoDB 中添加带有条件的子文档字段?

带有条件条件语句的总和在SQL中如何工作

如何在3D numpy数组中删除带有条件的元素行?

从Html组合框的值中查询带有条件的Select Sql

如何从带有条件的 React Native API 的数组结果中获取记录?

如何在mongodb中获取带有条件的多维数组的计数?

如何有条件地向 Angular 6 中的 HTML 元素添加属性

如何在带有条件的数组中呈现布尔值

如何从带有条件的文本文件中删除值

如何从带有条件的复杂字符串内容中捕获特定数据?

如何从laravel中有条件的3个表中获取所有数据?

如何在Heidi SQL中从多个表中选择带有条件的*

如何删除其他表中带有条件的行(SQL)

如何有条件地替换熊猫数据框列中的子字符串?

在Svelte 3中如何具有条件属性?

如何在角度2中有条件地分配属性值?

在SQL Server中查找具有条件的同一表上的值组合

如何在PostgreSQL中获取有条件的最后一个值?

如何有条件地联接并从联接表中获取数据?

如何根据反应选择中的选定值有条件地呈现数据

如何有条件地替换数据框中的 NaN 值?

如何使用if / then语句有条件地替换r数据框中的值

如何有条件地替换数据框中的值?