Update the XML nodes based on the node value in SQL Server
In my table I have col 1 ,col 2 ,col 3
. The col 3
has the XML stored. I want update the Name,Signedby,userid,title,status,lastmodified
nodes based on "Name" node.
XML File:
<SignatureSummary>
<SectionList>
<Section>
<Name>A</Name>
<SignedBy></SignedBy>
<UserId></UserId>
<Title><开发者_StackOverflow/Title>
<Status></Status>
<LastModifiedOn></LastModifiedOn>
</Section>
<Section>
<Name>B</Name>
<SignedBy />
<UserId />
<Title />
<Status />
<LastModifiedOn />
</Section>
</SectionList>
</SignatureSummary>
Try something like this:
SELECT
Col1, Col2,
Section.value('(Name)[1]', 'VARCHAR(50)') AS 'Name',
Section.value('(SignedBy)[1]', 'VARCHAR(50)') AS 'SignedBy',
Section.value('(UserId)[1]', 'VARCHAR(50)') AS 'UserId',
Section.value('(Title)[1]', 'VARCHAR(50)') AS 'Title',
Section.value('(Status)[1]', 'VARCHAR(50)') AS 'Status',
Section.value('(LastModifiedOn)[1]', 'DATETIME') AS 'Last Modified On'
FROM
dbo.YourTable
CROSS APPLY
Col3.nodes('/SignatureSummary/SectionList/Section') AS Sig(Section)
精彩评论