gpt4 book ai didi

sql-server - 在 T-SQL 中连接来自 XML 的数据

转载 作者:数据小太阳 更新时间:2023-10-29 01:46:55 24 4
gpt4 key购买 nike

我有以下 XML 消息:

DECLARE @XML AS XML
SET @XML =
'<Message>
<Changes>
<Deleted>
<ROW id="1" name="Nicole" surname="Bartlett" city="denver" balance="779.4663" dateOfBirth="1991-12-11T14:05:42.830" maritalStatus="S" />
<ROW id="1" name="Nicole" surname="Bartlett" city="boston" balance="779.4663" dateOfBirth="1991-12-11T14:05:42.830" maritalStatus="S" />
</Deleted>
<Inserted>
<ROW id="1" name="Nicole" surname="Bartlett" city="denver" balance="779.4663" dateOfBirth="1991-12-11T14:05:42.830" maritalStatus="S" />
<ROW id="1" name="Nicole" surname="Bartlett" city="boston" balance="779.4663" dateOfBirth="1991-12-11T14:05:42.830" maritalStatus="S" />
</Inserted>
</Changes>
</Message>'

我需要从这条消息中选择数据并加入另一个表的 id 字段。以下代码不起作用:

SELECT T.c.value('./@id', 'int') as id, t.c.value('./@name', 'varchar(max)') as name 
FROM @XML.nodes('/Message/Changes/Deleted/ROW') T(c)
inner join other_table tbl
on tbl.id = id

我该怎么做?

最佳答案

SELECT T.c.value('./@id', 'int') as id, t.c.value('./@name', 'varchar(max)') as name 
FROM @XML.nodes('/Message/Changes/Deleted/ROW') T(c)
inner join other_table tbl
on tbl.id = T.c.value('./@id', 'int')

关于sql-server - 在 T-SQL 中连接来自 XML 的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10498300/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com