将 XML 分解为 SQL 表时遇到问题

发布于 2024-12-02 00:00:03 字数 1762 浏览 1 评论 0原文

使用 SQL Server 2008,我需要将此 XML 选择到表中。我无法让它返回每一行。

Declare @CurrentStatusInfoList xml
Set @CurrentStatusInfoList = '<CurrentStatusInfoList>
  <CurrentStatusInfo Caption="Route" ItemID="568" eFolderID="0900000000000000000000000058170" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="615" eFolderID="0900000000000000000000000059580" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="1199" eFolderID="0900000000000000000000000066117" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="997" eFolderID="0900000000000000000000000063447" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="1208" eFolderID="0900000000000000000000000066265" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="1577" eFolderID="0900000000000000000000000069853" eStageName="ustg_Route" /> 
</CurrentStatusInfoList>'

 DECLARE @StatusTable 
    TABLE(           
             eFolderID varchar(100),
             ItemID bigint,
             eStageName varchar(100),
             Caption varchar(100)
         )

 INSERT INTO              
  @StatusTable (eFolderID, ItemID,eStageName,Caption)              
 SELECT               
  @CurrentStatusInfoList.value('(//@eFolderID)[1]', 'varchar(100)') as eFolderID,
  @CurrentStatusInfoList.value('(//@ItemID)[1]', 'bigint') as ItemID,
  @CurrentStatusInfoList.value('(//@eStageName)[1]', 'varchar(100)') as eStageName, 
  @CurrentStatusInfoList.value('(//@Caption)[1]', 'varchar(100)') as Caption 
FROM @CurrentStatusInfoList.nodes('//CurrentStatusInfoList/CurrentStatusInfo') 
    AS ParamValues(eFolderID)                 

 Select * from @StatusTable 

Using SQL Server 2008, I need to select this XML into a Table. I can't get it to return each row.

Declare @CurrentStatusInfoList xml
Set @CurrentStatusInfoList = '<CurrentStatusInfoList>
  <CurrentStatusInfo Caption="Route" ItemID="568" eFolderID="0900000000000000000000000058170" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="615" eFolderID="0900000000000000000000000059580" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="1199" eFolderID="0900000000000000000000000066117" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="997" eFolderID="0900000000000000000000000063447" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="1208" eFolderID="0900000000000000000000000066265" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="1577" eFolderID="0900000000000000000000000069853" eStageName="ustg_Route" /> 
</CurrentStatusInfoList>'

 DECLARE @StatusTable 
    TABLE(           
             eFolderID varchar(100),
             ItemID bigint,
             eStageName varchar(100),
             Caption varchar(100)
         )

 INSERT INTO              
  @StatusTable (eFolderID, ItemID,eStageName,Caption)              
 SELECT               
  @CurrentStatusInfoList.value('(//@eFolderID)[1]', 'varchar(100)') as eFolderID,
  @CurrentStatusInfoList.value('(//@ItemID)[1]', 'bigint') as ItemID,
  @CurrentStatusInfoList.value('(//@eStageName)[1]', 'varchar(100)') as eStageName, 
  @CurrentStatusInfoList.value('(//@Caption)[1]', 'varchar(100)') as Caption 
FROM @CurrentStatusInfoList.nodes('//CurrentStatusInfoList/CurrentStatusInfo') 
    AS ParamValues(eFolderID)                 

 Select * from @StatusTable 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

残龙傲雪 2024-12-09 00:00:03

试试这个:

Declare @CurrentStatusInfoList xml
Set @CurrentStatusInfoList = '<CurrentStatusInfoList>
  <CurrentStatusInfo Caption="Route" ItemID="568" eFolderID="0900000000000000000000000058170" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="615" eFolderID="0900000000000000000000000059580" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="1199" eFolderID="0900000000000000000000000066117" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="997" eFolderID="0900000000000000000000000063447" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="1208" eFolderID="0900000000000000000000000066265" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="1577" eFolderID="0900000000000000000000000069853" eStageName="ustg_Route" /> 
</CurrentStatusInfoList>'

 DECLARE @StatusTable 
    TABLE(           
             eFolderID varchar(100),
             ItemID bigint,
             eStageName varchar(100),
             Caption varchar(100)
         )

 INSERT INTO              
  @StatusTable (eFolderID, ItemID,eStageName,Caption)              
 SELECT               
  CurrentStatusInfo.value('@eFolderID', 'varchar(100)') as eFolderID,
  CurrentStatusInfo.value('@ItemID', 'bigint') as ItemID,
  CurrentStatusInfo.value('@eStageName', 'varchar(100)') as eStageName, 
  CurrentStatusInfo.value('@Caption', 'varchar(100)') as Caption 
FROM @CurrentStatusInfoList.nodes('//CurrentStatusInfoList/CurrentStatusInfo') as CurrentStatusInfoList(CurrentStatusInfo)

 Select * from @StatusTable 

Try this:

Declare @CurrentStatusInfoList xml
Set @CurrentStatusInfoList = '<CurrentStatusInfoList>
  <CurrentStatusInfo Caption="Route" ItemID="568" eFolderID="0900000000000000000000000058170" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="615" eFolderID="0900000000000000000000000059580" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="1199" eFolderID="0900000000000000000000000066117" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="997" eFolderID="0900000000000000000000000063447" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="1208" eFolderID="0900000000000000000000000066265" eStageName="ustg_Route" /> 
  <CurrentStatusInfo Caption="Route" ItemID="1577" eFolderID="0900000000000000000000000069853" eStageName="ustg_Route" /> 
</CurrentStatusInfoList>'

 DECLARE @StatusTable 
    TABLE(           
             eFolderID varchar(100),
             ItemID bigint,
             eStageName varchar(100),
             Caption varchar(100)
         )

 INSERT INTO              
  @StatusTable (eFolderID, ItemID,eStageName,Caption)              
 SELECT               
  CurrentStatusInfo.value('@eFolderID', 'varchar(100)') as eFolderID,
  CurrentStatusInfo.value('@ItemID', 'bigint') as ItemID,
  CurrentStatusInfo.value('@eStageName', 'varchar(100)') as eStageName, 
  CurrentStatusInfo.value('@Caption', 'varchar(100)') as Caption 
FROM @CurrentStatusInfoList.nodes('//CurrentStatusInfoList/CurrentStatusInfo') as CurrentStatusInfoList(CurrentStatusInfo)

 Select * from @StatusTable 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文