0

好的,我有一个表,其中有一列名为bdParameters,数据类型为text。列中存储的数据bdParameters是保存为文本的 XML。

数据是这样的:

<root>
    <row statusID="ALL" subID="ALL" viewMaskFields="false" masID="219" 
         userID="13" prptyDate="08/19/2011" docID="21b15c9e-76a5-44ed-afbb-96b6df2cf881" 
         resmID="8806" leaID="6345" reshID="3560" doEmail="" emailFrom="" emailTo="" 
         emailMsg="penarands" emailSubject="" fieldList="1" fmtID="2" OptInCES="Yes" 
         SendVaiEmailCES="1" RPIPMCURL="blabla@blabla.com" />
    <Custom>
       <UpdateResidentLetter>
          <Row Status="NOTPRINTED" Notes="Created from bulk lettersinterface" />
       </UpdateResidentLetter>
    </Custom>
</root>

我希望能够仅从emailMsg该 xml 中选择属性。

那可能吗?如果是这样,怎么做?

4

1 回答 1

0

使用 xml.value 和@符号来获取属性

declare @t table (col xml);
insert @t select '
<root><row statusID="ALL" subID="ALL" viewMaskFields="false" masID="219" 
userID="13" prptyDate="08/19/2011" docID="21b15c9e-76a5-44ed-afbb-96b6df2cf881" 
resmID="8806" leaID="6345" reshID="3560" doEmail="" emailFrom="" emailTo="" 
emailMsg="penarands" emailSubject="" fieldList="1" fmtID="2" OptInCES="Yes" 
SendVaiEmailCES="1" RPIPMCURL="lm-10-254-9-52.onesitedev.realpage.com" /><Custom>
<UpdateResidentLetter><Row Status="NOTPRINTED" Notes="Created from bulk letters
 interface" /></UpdateResidentLetter></Custom></root>';

select col.value('(/root/row/@emailMsg)[1]','varchar(max)') emailMsg
from @t

-- result
penarands
于 2012-09-28T02:12:15.330 回答