2012-09-28 82 views
0

好吧,我有一個表有一個名爲bdParameters的列,數據類型爲text。存儲在bdParameters列中的數據以XML格式保存爲文本。從SQL中選擇屬性中的一個屬性

的數據是這樣的:

<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="[email protected]" /> 
    <Custom> 
     <UpdateResidentLetter> 
      <Row Status="NOTPRINTED" Notes="Created from bulk lettersinterface" /> 
     </UpdateResidentLetter> 
    </Custom> 
</root> 

我希望能夠選擇只從XML屬性emailMsg

這可能嗎?如果是這樣,怎麼樣?

回答

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