如何从存储过程中的XML中获取价值?

时间:2014-11-10 03:22:01

标签: sql xml stored-procedures

你能帮我解决这个问题吗? 我想从sql存储过程中的XML中获取值。如果&x; xsi:type =" ActiveDirectoryItem"'是标记' anyType'和' ActiveDirectoryItems'标签也带有URL。我怎么能只获得价值?

<?xml version="1.0" encoding="utf-8" ?> 
<ActiveDirectoryItems xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<Items>
<anyType xsi:type="ActiveDirectoryItem">
  <FirstName /> 
  <MiddleInitial /> 
  <LastName />
  <DisplayName>Migrate-group</DisplayName> 
  <UserPrincipalName /> 
  <PostalAddress /> 
  <ResidentialAddress />
  <Title />
  <HomePhone />
  <OfficePhone />
  <Mobile />   
  <Fax /> 
  <Email>Migrate-group@gmail.com</Email> 
  <Url /> 
  <AccountName>Migrate-group</AccountName> 
  <DistinguishedName /> 
  <IsAccountActive>false</IsAccountActive> 
  <ManagedBy /> 
  <Manager /> 
  <CompareType>0</CompareType> 
  <Description /> 
  <Department /> 
  <Company /> 
  <Type /> 
  </anyType>
  </Items>
 <GlobalCatalog /> 
 </ActiveDirectoryItems>

我想获得的格式如下:

DisplayName         Email                          Account Name
Migrate-group       Migrate-group@gmail.com     Migrate-group

1 个答案:

答案 0 :(得分:0)

您可以使用value关键字

示例:

DECLARE @MyXml XML = '<Root><SomeData>100</SomeData></Root>'

DECLARE @Something INT
SELECT @Something = @MyXml.value('(//Root/SomeData)[1]', 'INT')