Querying XML Columns in SQL Server 2005

In my company "Contacts" there is a field. This table has an XML type column. The column contains different information about a specific contact. EG.

<contact>
<refno>123456</refno>
<special>a piece of custom data</special>
</contact>

The tags below contactmay be different for each contact, and I have to query for these fragments along with columns of relational data in the same table.

I used constructs such as:

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

This method works fine, but the server takes time. I also explored using the nodes () function to parse the XML nodes and exist () to check if the node supports the value I'm looking for.

Does anyone know a better way to query XML columns?

+3
source share
5 answers

, , . , , name/value/contactID.

+3

, @pauljette, :

http://msdn.microsoft.com/en-us/library/ms345118.aspx

, XML-, , . , , , , -, ( ).

0

XSD Xml, , Xml.

0

SELECT * FROM conversionupdatelog WHERE to convert (XML, colName) .value ('(/ leads / leads / @ LeadID =' ' xyz@airproducts.com ' ') [1]', 'varchar (max)') = 'true'

0
source

Source: https://habr.com/ru/post/1696756/


All Articles