我有一个存储过程,它读取一些 ID 并从表中获取与这些 ID 关联的 XML 值。
USE [Database]
GO
/****** Object: StoredProcedure [dbo].[GetLetterIssueTcm] Script Date: 03/31/2014 12:07:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create PROCEDURE [dbo].[GetLetterIssueTcm]
@LetterIds varchar(5000)
AS
Declare @SQL VarChar(1000)
select @SQL = 'Select content from component_presentations where publication_id = 80
and template_id = 41064 and component_id in (' + @LetterIds +')'
Exec ( @SQL)
LetterIds 是一个以逗号分隔的 ID 字符串,例如“55773,52663” 此存储过程返回的内容包含每个 LetterId 的 XML。 XML 如下所示:
<letterIssue>
<Date>2010-12-01T00:00:00</Date>
<Items>
<Item id="tcm:80-74757"></Item>
<Item id="tcm:80-74760"></Item>
<Item id="tcm:80-74766"></Item>
<Item id="tcm:80-74770"></Item>
<Item id="tcm:80-74772"></Item>
</Items>
</letterIssue>
现在我想创建一个虚拟表,该表的一列中包含字母 Id,第二行包含该字母 Id 的 xml 中的关联项目 Id。像这样的东西:
LetterId Item_Id
55773 tcm:80-74757
55773 tcm:80-74760
这可以在同一个存储过程中完成,或者我不介意将此存储过程的输出(多个 xml)传递给另一个存储过程,然后检索与其关联的项目 ID。那么我该如何处理多个 xml 并从中找到项目 ID?
最佳答案
类似这样的吗?
select component_id, i.i.value('@id', 'varchar(100)') as item
from component_presentations t
outer apply t.content.nodes('/letterIssue[1]/Items[1]/Item')i(i)
where publication_id = 80 and template_id = 41064 and
component_id in (55773,66884)
附注如果有一天您收到 @LetterIds = '55773;drop table component_presentations'
,您会怎么做?
关于mysql - 将多个 xml 传递给存储过程并检索 xml 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22755113/