Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're using a recent version of SQL Server, there's a new column data type (XML).</p> <p>You can apply xpath to it, making querying the column much easier.</p> <p>Instead of trying to store the XML as a string in your DB, I'd suggest you actually store it as XML, and treat it as XML.</p> <p>There is a learning curve. You'll need to be familiar with XPATH, but it's not rocket science.</p> <p>an example: </p> <pre><code>SELECT Id, PartitionMonth, EmailAddress, AcquisitionCodeId, FieldValues.value(' declare namespace s="http://domain.com/FieldValues.xsd"; data(/s:FieldValues/s:item/@value)[1]', 'varchar(200)') FROM Leads.Leads WITH (NOLOCK) WHERE Id = 190708 </code></pre> <p>Another example retrieving values by key: </p> <pre><code>SELECT r.EmailAddress, ar.Ip, ar.DateLog, ar.FieldValues.value(' declare namespace s="http://domain.com/FieldValues.xsd"; data(/s:FieldValues/s:item[@key="First Name"]/@value)[1]', 'varchar(20)') FirstName, ar.FieldValues.value(' declare namespace s="http://domain.com/FieldValues.xsd"; data(/s:FieldValues/s:item[@key="Last Name"]/@value)[1]', 'varchar(20)') LastName FROM Records.Records r WITH (NOLOCK) JOIN Records.AcquisitionRecords ar WITH (NOLOCK) ON r.Id = ar.Id WHERE ar.AcquisitionCodeId IN (19, 21, 30, 34, 36) AND ar.DateLog BETWEEN '1-mar-09' AND '31-mar-09' </code></pre> <p>A good place to get started on XML in SQL Server <a href="http://msdn.microsoft.com/en-US/library/ms189887(v=sql.90).aspx" rel="nofollow">http://msdn.microsoft.com/en-US/library/ms189887(v=sql.90).aspx</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload