我有一个如下所示的 xml 数据.
DECLARE @XmlContent XML设置@XmlContent ='<实体><实体类型=5"><item id="1"/><item id="2"/><item id="2"/></实体><实体类型=6"><item id="3"/><item id="4"/><item id="5"/></实体></实体>'我想从中选择数据并按以下格式插入表格 -
<前>------------类型 ID------------5 15 25 26 36 46 5有人可以帮我在 sql server 中为此编写查询吗?
selectent.value('@type', 'int') 作为类型,row.value('@id', 'int') 作为 ID从@XmlContent.nodes('/Entities/Entity') foo(ent)交叉应用 ent.nodes('item') bar(row)I have an xml data that looks like below.
DECLARE @XmlContent XML
SET @XmlContent =
'<Entities>
<Entity type = "5">
<item id ="1"/>
<item id ="2"/>
<item id ="2"/>
</Entity>
<Entity type = "6">
<item id ="3"/>
<item id ="4"/>
<item id ="5"/>
</Entity>
</Entities>'
I want to select data from this and insert into a table in the following format -
------------ Type Id ------------ 5 1 5 2 5 2 6 3 6 4 6 5
Can some one help me to write query for this in sql server?
select
ent.value('@type', 'int') as Type,
row.value('@id', 'int') as ID
from
@XmlContent.nodes('/Entities/Entity') foo(ent)
cross apply ent.nodes('item') bar(row)
这篇关于查询@xml 变量以获取行集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
获取所有产品、类别和元数据的 SQL 查询 woocommSQL query to get all products, categories and meta data woocommerce/wordpress(获取所有产品、类别和元数据的 SQL 查询 woocommerce/wordpre
我可以在不编写 SQL 查询的情况下找出数据库列表Can I figure out a list of databases and the space used by SQL Server instances without writing SQL queries?(我可以在不编写 SQL 查询的情况下
如何创建对 SQL Server 实例的登录?How to create a login to a SQL Server instance?(如何创建对 SQL Server 实例的登录?)
如何通过注册表搜索知道SQL Server的版本和版本How to know the version and edition of SQL Server through registry search(如何通过注册表搜索知道SQL Server的版本和版本)
为什么会出现“数据类型转换错误"?使用 ExWhy do I get a quot;data type conversion errorquot; with ExecuteNonQuery()?(为什么会出现“数据类型转换错误?使用 ExecuteNonQuery()?)
如何将 DataGridView 中的图像显示到 PictureBox?How to show an image from a DataGridView to a PictureBox?(如何将 DataGridView 中的图像显示到 PictureBox?)