問題描述
我公司的聯系人"表中有一個字段.在該表中,有一個 XML 類型列.該列包含有關特定聯系人的雜項數據.例如.
There is a field in my company's "Contacts" table. In that table, there is an XML type column. The column holds misc data about a particular contact. EG.
<contact>
<refno>123456</refno>
<special>a piece of custom data</special>
</contact>
contact
下面的標簽對于每個聯系人可以不同,我必須查詢這些片段同一個表中的關系數據列.
The tags below contact
can be different for each contact, and I must query these fragments
alongside the relational data columns in the same table.
我使用過如下結構:
SELECT c.id AS ContactID,c.ContactName as ForeName,
c.xmlvaluesn.value('(contact/Ref)[1]', 'VARCHAR(40)') as ref,
INNER JOIN ParticipantContactMap pcm ON c.id=pcm.contactid
AND pcm.participantid=2140
WHERE xmlvaluesn.exist('/contact[Ref = "118985"]') = 1
這個方法沒問題,但是服務器需要一段時間來響應.我還研究了使用 nodes() 函數來解析 XML 節點并使用exist() 來測試節點是否包含我正在搜索的值.
This method works ok but, it takes a while for the Server to respond. I have also investigated using the nodes() function to parse the XML nodes and exist() to test if a nodes holds the value I'm searching for.
有人知道查詢 XML 列的更好方法嗎??
Does anyone know a better way to query XML columns??
推薦答案
我發現 msdn xml 最佳實踐有助于處理 xml blob 列,可能會提供一些靈感...http://msdn.microsoft.com/en-us/library/ms345115.aspx#sql25xmlbp_topic4
I've found the msdn xml best practices helpful for working with xml blob columns, might provide some inspiration... http://msdn.microsoft.com/en-us/library/ms345115.aspx#sql25xmlbp_topic4
這篇關于在 SQLServer 2005 中查詢 XML 列的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!