Isaac 8/9/2011 7:24:59 AM

How to read an attribute from an XML field in SQL Server 2005

This tip explains how to read an XML attribute from an XML field in sql server. Or, put another way, if we have this data:

<Receivable documentNumber="PYMNT000000000012    " documentDate="12/13/2007">
  <Type>PAYMENT</Type>
  <CashType>CHECK</CashType>
  <Description />
  <CheckNumber />
  <Amount>3.00000</Amount>
  <AppliedAmount>3.00000</AppliedAmount>
  <UnappliedAmount>0.00000</UnappliedAmount>
  <Items />
</Receivable>

 

We want to use SQL Server 2005 to retrieve the document number (PYMNT000000000012)

The code looks like this:

 

Version: Unknown or N/A
Section: SQL Scripts


Table Definition Quick Links
All Tables
SOP Tables
RM Tables
GL Tables
POP Tables
HR Tables
PM Tables
UPR Tables
IV Tables
Olympic Tables
3