TSQL Parse from XML nodes - sql-server

This XML comes from public treasury. SQL Server seems to think it is not XML? My result says the XLT method can only be involved with column type XML. Is this result set from the treasury really XML?
How can I parse it into a SQL table?
treasury daily market yield
DECLARE #XML NVARCHAR(MAX)
SELECT #XML =
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<feed xml:base="http://data.treasury.gov/Feed.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<title type="text">DailyTreasuryYieldCurveRateData</title>
<id>http://data.treasury.gov/feed.svc/DailyTreasuryYieldCurveRateData</id>
<updated>2020-07-14T05:40:26Z</updated>
<link rel="self" title="DailyTreasuryYieldCurveRateData" href="DailyTreasuryYieldCurveRateData"/>
<entry>
<id>http://data.treasury.gov/Feed.svc/DailyTreasuryYieldCurveRateData(7633)</id>
<title type="text"/>
<updated>2020-07-14T05:40:26Z</updated>
<author>
<name/>
</author>
<link rel="edit" title="DailyTreasuryYieldCurveRateDatum" href="DailyTreasuryYieldCurveRateData(7633)"/>
<category term="TreasuryDataWarehouseModel.DailyTreasuryYieldCurveRateDatum" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<content type="application/xml">
<m:properties>
<d:Id m:type="Edm.Int32">7633</d:Id>
<d:NEW_DATE m:type="Edm.DateTime">2020-07-01T00:00:00</d:NEW_DATE>
<d:BC_1MONTH m:type="Edm.Double">0.12</d:BC_1MONTH>
<d:BC_2MONTH m:type="Edm.Double">0.12</d:BC_2MONTH>
<d:BC_3MONTH m:type="Edm.Double">0.14</d:BC_3MONTH>
<d:BC_6MONTH m:type="Edm.Double">0.17</d:BC_6MONTH>
<d:BC_1YEAR m:type="Edm.Double">0.16</d:BC_1YEAR>
<d:BC_2YEAR m:type="Edm.Double">0.17</d:BC_2YEAR>
<d:BC_3YEAR m:type="Edm.Double">0.19</d:BC_3YEAR>
<d:BC_5YEAR m:type="Edm.Double">0.31</d:BC_5YEAR>
<d:BC_7YEAR m:type="Edm.Double">0.52</d:BC_7YEAR>
<d:BC_10YEAR m:type="Edm.Double">0.69</d:BC_10YEAR>
<d:BC_20YEAR m:type="Edm.Double">1.2</d:BC_20YEAR>
<d:BC_30YEAR m:type="Edm.Double">1.43</d:BC_30YEAR>
<d:BC_30YEARDISPLAY m:type="Edm.Double">1.43</d:BC_30YEARDISPLAY>
</m:properties>
</content>
</entry>
</feed>'
SELECT b.value('#d:Id', 'varchar(28)') as d_id
,b.value('#d:BC_30YEAR', 'double') as d_BC_30YEAR
FROM #XML.nodes('feed/entry/content type/m:properties/') as a(b)

First, define your #XML to be of type XML:
DECLARE #XML XML;
Then: you need to define the relevant XML namespaces involved!
Try this snippet of code:
-- define XML namespaces!
;WITH XMLNAMESPACES(DEFAULT 'http://www.w3.org/2005/Atom',
'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata' AS m,
'http://schemas.microsoft.com/ado/2007/08/dataservices' AS d)
SELECT
b.value('(d:Id)[1]', 'varchar(28)') as d_id,
b.value('(d:BC_30YEAR)[1]', 'decimal(20,2)') as d_BC_30YEAR
FROM
#XML.nodes('feed/entry/content/m:properties') as a(b)
This returns the following value:
Fixes I made:
FROM #XML.nodes('feed/entry/content type/m:properties/') as a(b)
^^^^^^^^^^^^
Wrong node name - the node is <content> (not "content type") - the type is just an attribute on the node, no relevant in this XPath here.
SELECT b.value('#d:Id', 'varchar(28)') as d_id
^^^^^^
You really want to select the XML element (node) d:Id - not an attribute - the # in #d:Id denotes an attribute!
b.value('#d:BC_30YEAR', 'double') as d_BC_30YEAR
^^^^^^^^^
You need to use a proper T-SQL datatype - like decimal(20,2) - not "double"
here....

Related

Query to remove a tag in XML in SQL Server

I have a xml with name space as follows. How do I remove the tag <ns1:replyTo> from the XML using XML query. Can we remove the tag with something like below query. Am not sure how to pass through the tags with SOAP-ENV
update tablename
set XMLColumnname.modify(('delete /ServiceIn/file/sender/replyTo[1]'))
XML:
<?xml version="1.0"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:si="http://someservice.abc.com/stds/xyz/a1"
xmlns:oas="http://docs.oasis-open.org/abc/2004/01/oasis-200401-abc-abcsecurity-xyz- 1.0.xsd">
<SOAP-ENV:Header>
<oas:Security>
<oas:Credential>
<oas:name>%s</oas:name>
<oas:Password>%s</oas:Password>
</oas:Credential>
</oas:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:execute
xmlns:ns1="urn:com.company.us.abc.service.xyz.someService">
<si:ServiceRequestInfo>
<si:Tag1 />
<si:Tag2 />
<si:Tag3 />
<si:Tag4 />
</si:ServiceRequestInfo>
<ns1:ServiceIn>
<ns1:Tag5>%s</ns1:Tag5>
<ns1:File>
<ns1:Sender>
<ns1:Name>%s</ns1:Name>
<ns1:Email>%s</ns1:Email>
<ns1:replyTo>%s</ns1:replyTo>
</ns1:Sender>
</ns1:File>
</ns1:ServiceIn>
</ns1:execute>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Your current XQuery path is anonymous and also starts at the wrong root.
You need to define the required namespaces using with xmlnamespaces or declare the namespaces inside the XQuery statement itself, e.g.:
create table tablename (
XMLColumnname xml
);
insert tablename values
(N'<?xml version="1.0"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:si="http://someservice.abc.com/stds/xyz/a1"
xmlns:oas="http://docs.oasis-open.org/abc/2004/01/oasis-200401-abc-abcsecurity-xyz- 1.0.xsd">
<SOAP-ENV:Header>
<oas:Security>
<oas:Credential>
<oas:name>%s</oas:name>
<oas:Password>%s</oas:Password>
</oas:Credential>
</oas:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:execute
xmlns:ns1="urn:com.company.us.abc.service.xyz.someService">
<si:ServiceRequestInfo>
<si:Tag1 />
<si:Tag2 />
<si:Tag3 />
<si:Tag4 />
</si:ServiceRequestInfo>
<ns1:ServiceIn>
<ns1:Tag5>%s</ns1:Tag5>
<ns1:File>
<ns1:Sender>
<ns1:Name>%s</ns1:Name>
<ns1:Email>%s</ns1:Email>
<ns1:replyTo>%s</ns1:replyTo>
</ns1:Sender>
</ns1:File>
</ns1:ServiceIn>
</ns1:execute>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>');
update tablename
set XMLColumnname.modify('declare namespace soap="http://schemas.xmlsoap.org/soap/envelope/";
declare namespace foo="urn:com.company.us.abc.service.xyz.someService";
delete /soap:Envelope/soap:Body/foo:execute/foo:ServiceIn/foo:File/foo:Sender/foo:replyTo[1]');
select * from tablename;
Which yields...
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:si="http://someservice.abc.com/stds/xyz/a1"
xmlns:oas="http://docs.oasis-open.org/abc/2004/01/oasis-200401-abc-abcsecurity-xyz- 1.0.xsd">
<SOAP-ENV:Header>
<oas:Security>
<oas:Credential>
<oas:name>%s</oas:name>
<oas:Password>%s</oas:Password>
</oas:Credential>
</oas:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:execute xmlns:ns1="urn:com.company.us.abc.service.xyz.someService">
<si:ServiceRequestInfo>
<si:Tag1 />
<si:Tag2 />
<si:Tag3 />
<si:Tag4 />
</si:ServiceRequestInfo>
<ns1:ServiceIn>
<ns1:Tag5>%s</ns1:Tag5>
<ns1:File>
<ns1:Sender>
<ns1:Name>%s</ns1:Name>
<ns1:Email>%s</ns1:Email>
</ns1:Sender>
</ns1:File>
</ns1:ServiceIn>
</ns1:execute>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

extract soap xml tag value containing multiple namespaces and different attribute in SQL Sever

Below is the sample SOAP xml and query to extract the value -
DECLARE #xml XML='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<xsi:MaintenanceOrder xmlns:xsi="http://schema.xyz.com/abc/2" xmlns:ush="http://www.xyz.nl/abc" xmlns:xsj="http://www.w3.org/2001/XMLSchema-instance" languageCode="en-US" releaseID="9.2" systemEnvironmentCode="Production" versionID="2.8.0">
<xsi:DataArea>
<xsi:MaintenanceOrder>
<xsi:MaintenanceOrderHeader>
<xsi:UserArea>
<xsi:Property>
<xsi:NameValue accountingEntity="*" listID="*" name="OrderDate" type="DATE">2020-03-30T00:00:00</xsi:NameValue>
</xsi:Property>
<xsi:Property>
<xsi:NameValue accountingEntity="*" listID="*" name="ReportDate" type="DATE">2020-04-30T00:00:00</xsi:NameValue>
</xsi:Property>
</xsi:UserArea>
</xsi:MaintenanceOrderHeader>
</xsi:MaintenanceOrder>
</xsi:DataArea>
</xsi:MaintenanceOrder>
</soapenv:Body>
</soapenv:Envelope>'
select A.r.value('(xsi:NameValue[#name="OrderDate"])[1]','date') as "OrderDate"
,A.r.value('(xsi:NameValue[#name="ReportDate"])[1]','date') as "ReportDate"
FROM #xml.nodes('/*:Envelope/*:Body/*:MaintenanceOrder/*:DataArea/*:MaintenanceOrder/*:MaintenanceOrderHeader/*:UserArea/*:Property') AS A(r)
issue 1 - by removing namespace in MaintenanceOrder only then query returns value otherwise returns null.
issue 2 - the required output is single line with multiple tags value, but the query is giving multiple rows.
Any help would be highly appreciated.
Try to use with xmlnamespaces declarations and explicit paths so that your XPath queries match only the elements you expect - and perform as well as can be expected.
For example:
declare #xml xml =
N'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<xsi:MaintenanceOrder xmlns:xsi="http://schema.xyz.com/abc/2" xmlns:ush="http://www.xyz.nl/abc" xmlns:xsj="http://www.w3.org/2001/XMLSchema-instance" languageCode="en-US" releaseID="9.2" systemEnvironmentCode="Production" versionID="2.8.0">
<xsi:DataArea>
<xsi:MaintenanceOrder>
<xsi:MaintenanceOrderHeader>
<xsi:UserArea>
<xsi:Property>
<xsi:NameValue accountingEntity="*" listID="*" name="OrderDate" type="DATE">2020-03-30T00:00:00</xsi:NameValue>
</xsi:Property>
<xsi:Property>
<xsi:NameValue accountingEntity="*" listID="*" name="ReportDate" type="DATE">2020-04-30T00:00:00</xsi:NameValue>
</xsi:Property>
</xsi:UserArea>
</xsi:MaintenanceOrderHeader>
</xsi:MaintenanceOrder>
</xsi:DataArea>
</xsi:MaintenanceOrder>
</soapenv:Body>
</soapenv:Envelope>';
with xmlnamespaces (
'http://schemas.xmlsoap.org/soap/envelope/' as s11,
'http://schema.xyz.com/abc/2' as abc
)
select
A.r.value('(abc:Property/abc:NameValue[#name="OrderDate"])[1]','date') as "OrderDate",
A.r.value('(abc:Property/abc:NameValue[#name="ReportDate"])[1]','date') as "ReportDate"
from #xml.nodes('/s11:Envelope/s11:Body/abc:MaintenanceOrder/abc:DataArea/abc:MaintenanceOrder/abc:MaintenanceOrderHeader/abc:UserArea') as A(r);
Returns the expected values in a single row:
OrderDate ReportDate
2020-03-30 2020-04-30

How to add additional attributes and XML namespaces value inside same root in SQL Server

I am trying to add attributes and xmlns using WITH XMLNAMESPACES under same root, but could not make it work. Please help.
The following SQL query throws an error
Msg 6852, Level 16, State 1, Line 17
Attribute-centric column '#encounter_number' must not come after a non-attribute-centric sibling in XML hierarchy in FOR XML PATH.
for this line
'HMSXML' AS "pbrc/#source" , URNumber AS "pbrc/#messageHash", 'xmlResult01' AS "pbrc/#integration_info"
Full code:
DECLARE #xml XML;
WITH XMLNAMESPACES (
'http://www.w3.org/2001/XMLSchema-instance' as xsi
,'http://java.sun.com/xml/ns/jaxb/xjc' as xjc
,'http://www.powerhealthsolutions.com/pbrc/jaxb/ext' as [pbrc-jaxb]
,'http://java.sun.com/xml/ns/jaxb' AS jaxb
,DEFAULT 'http://www.powerhealthsolutions.com/pbrc')
SELECT
#xml = (SELECT
'HMSXML' AS "pbrc/#source",
URNumber AS "pbrc/#messageHash",
'xmlResult01' AS "pbrc/#integration_info",
AdmissionID AS "#encounter_number",
'NDIS' AS organisation_code,
'NDIS' AS encounter_type,
(SELECT
'true' AS "#delete",
(SELECT 'NDIS' AS class_type, AdmissionDate AS start_date_time
FOR XML PATH ('financial_class'), TYPE)
FOR XML PATH('financial_classes'), TYPE),
(SELECT
URNumber AS "#entity_number",
(SELECT 'NDIS ID' AS name, NDISNumber AS value
FOR XML PATH ('extra'), ROOT('extras'), TYPE)
FOR XML PATH ('recipient'), TYPE),
'H' AS referral_source,
'H' AS separation_status,
AdmissionDate AS start_date_time
FROM
Episode
FOR XML PATH('encounter'), ROOT('pbrc'), TYPE)
select #xml
I want to get output as shown here, but I'm failing to achieve those last 3 attributes integration_info="xmlResult03", messageHash="4208151" and source="HMSXML". These will come from SQL select query.
<?xml version="1.0"?>
-<pbrc xmlns="http://www.powerhealthsolutions.com/pbrc" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:pbrc-jaxb="http://www.powerhealthsolutions.com/pbrc/jaxb/ext" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" integration_info="xmlResult03" messageHash="4208151" source="HMSXML">
-<encounter encounter_number="525241">
<organisation_code>NDIS</organisation_code>
<encounter_type>NDIS</encounter_type>
-<financial_classes delete="true">
-<financial_class>
<class_type>NDIS</class_type>
<start_date_time>2018-06-26T00:00:00</start_date_time>
</financial_class>
</financial_classes>
-<payors>
-<payor>
<payor entity_number="4208151"> </payor>
<slot>Patient</slot>
<start_date>2018-06-26</start_date>
</payor>
</payors>
-<recipient entity_number="4208151">
-<extras>
-<extra>
<name>NDIS ID</name>
<value>430392519</value>
</extra>
</extras>
</recipient>
<referral_source>H</referral_source>
<separation_status>H</separation_status>
-<services>
-<service>
<source_system_code>HMSXML</source_system_code>
<organisation_code>NDIS</organisation_code>
<actual_charge>179.26</actual_charge>
<description1>Arnold Sch - Occupational Therapist</description1>
<quantity>1</quantity>
<service_code>15_048_0128_1_3</service_code>
<start_time>2019-03-27T15:00:00</start_time>
</service>
-<service>
<source_system_code>HMSXML</source_system_code>
<organisation_code>NDIS</organisation_code>
<actual_charge>193.99</actual_charge>
<description1>Arnold Sch - Occupational Therapist</description1>
<quantity>1</quantity>
<service_code>15_056_0128_1_3</service_code>
<start_time>2019-07-30T15:00:00</start_time>
</service>
</services>
<start_date_time>2018-06-26T00:00:00</start_date_time>
</encounter>
</pbrc>

How to query XML in T-SQL with inline ID

I have this XML stored in a record, how can I get a value of a specific ID?
<Attributes>
<CustomerAttribute ID="4">
<CustomerAttributeValue>
<Value>1</Value>
</CustomerAttributeValue>
</CustomerAttribute>
<CustomerAttribute **ID="5"**>
<CustomerAttributeValue>
<Value>**aaaaa**</Value>
</CustomerAttributeValue>
</CustomerAttribute>
Assuming the ** surrounding ID="5" and "aaaaa" denotes the nodes you want to select, below is one method.
SELECT XmlColumn.value('(/Attributes/CustomerAttribute[#ID="5"]/CustomerAttributeValue/Value)[1]', 'varchar(100)')
FROM dbo.xml
WHERE XmlColumn.exist('/Attributes/CustomerAttribute[#ID="5"]') = 1;
This assumes the actual XML value is like:
<Attributes>
<CustomerAttribute ID="4">
<CustomerAttributeValue>
<Value>1</Value>
</CustomerAttributeValue>
</CustomerAttribute>
<CustomerAttribute ID="5">
<CustomerAttributeValue>
<Value>aaaaa</Value>
</CustomerAttributeValue>
</CustomerAttribute>
</Attributes>

Querying XML within SQL Server with namespace

I'm trying to query some XML data that I was sent. I have followed various examples, but can't even address any of the elements beneath the root. I'm not sure what I'm missing. I've tried simply pulling the xml beneath /KitchenSupply/StoreInfo and nothing. Is the namespace the culprit for me not being able to return anything?
declare #myxmlinv as xml =
'<?xml version="1.0" encoding="utf-8"?>
<KitchenSupply xmlns="http://www.starstandards.org/STAR" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="KitchenSupply.xsd">
<StoreInfo>
<RCPT>
<SubTaskCode>ZZZ</SubTaskCode>
<SubComponentCode>BS1</SubComponentCode>
<StoreNumber>2241</StoreNumber>
<USRegionNumber>SE</USRegionNumber>
</RCPT>
<SentDateTime>02/04/2015</SentDateTime>
<IntId>ABC1234587</IntId>
<Destinations>
<DestinationFormatType>KS_XML_v3</DestinationFormatType>
</Destinations>
</StoreInfo>
<KitchenOrder>
<KsRecord SalesTransactionPayType="CC" SalesTransactionType="Closed">
<ReceiptAmt RcptTotalAmt="0.00" CustRcptTotalAmt="25.22" CCPostDate="01/07/2015" InvoiceDate="01/05/2015" CustName="JOHN SMITH" CustNo="13998" RcptNo="78476221" />
<KsCosts>
<SaleAmts UnitCost="15.00" TxblAmt="15.00" PayType="Cust" />
<SalesInfo JobStatus="F" JobNo="1" ItemCode="HT093" ItemDesc="Hand Towel">
<EmpInfo EmpRate="16.00" EmpCommPct="1.2" EmpName="DOUG ROGERS" EmpNo="998331" />
</SalesInfo>
</KsCosts>
</KsRecord>
<CustomerRecord>
<ContactInfo LastName="SMITH" FreqFlag="Y">
<Address Zip="90210" State="CA" City="BEV" Addr1="123 MAIN ST" Type="Business" />
<Email MailTo="FAKE#USA.COM" />
<Phone Num="1235551212" Type="H" />
<Phone Num="1235551213" Type="B" />
</ContactInfo>
</CustomerRecord>
</KitchenOrder>
<KitchenOrder>
<KsRecord SalesTransactionPayType="CC" SalesTransactionType="Closed">
<ReceiptAmt RcptTotalAmt="0.00" CustRcptTotalAmt="5.71" CCPostDate="01/08/2015" InvoiceDate="01/07/2015" CustName="SARAH BALDWIN" CustNo="14421" RcptNo="78476242" />
<KsCosts>
<SaleAmts UnitCost="2.00" TxblAmt="2.00" PayType="Cust" />
<SalesInfo JobStatus="F" JobNo="1" ItemCode="HS044" ItemDesc="Hand Soap">
<EmpInfo EmpRate="16.00" EmpCommPct="1.2" EmpName="DOUG ROGERS" EmpNo="998331" />
</SalesInfo>
</KsCosts>
</KsRecord>
<CustomerRecord>
<ContactInfo LastName="BALDWIN" FreqFlag="N">
<Address Zip="90210" State="CA" City="BEV" Addr1="123 VINE ST" Type="Home" />
<Email MailTo="FAKESARAH#USA.COM" />
<Phone Num="1235555512" Type="H" />
<Phone Num="1235556613" Type="M" />
</ContactInfo>
</CustomerRecord>
</KitchenOrder>
</KitchenSupply>';
declare #myxmlinv_table as table (
row_id tinyint,
inv_xml xml
);
insert into #myxmlinv_table(row_id,inv_xml) values('1',#myxmlinv);
Display the XML document and pull the IntId column: (doesn't work)
select i.row_id, i.inv_xml, i.inv_xml.value('(/KitchenSupply/StoreInfo/IntId)[1]','varchar(255)') as data_description
from #myxmlinv_table i
Attempt to use XMLNAMESPACES to display the XML document at the StoreInfo level: (also doesn't work)
WITH XMLNAMESPACES ('http://www.starstandards.org/STAR' as ks)
SELECT
XmlCol.query('/ks:KitchenSupply/StoreInfo')
FROM T;
Ideally, I'd like to use the nodes to extract all the data out and in to separate tables for querying.
KitchenOrders all within one table, CustomerRecord within another, etc.
Any ideas?
You need to use something like this:
-- define the XML namespace as the "default" so you don't have to
-- prefix each and every XPath element with the XML namespace prefix
WITH XMLNAMESPACES( DEFAULT 'http://www.starstandards.org/STAR')
SELECT
-- reach into the <KsRecord> subnode under <KitchenOrder>
ReceiptNo = XC.value('(KsRecord/ReceiptAmt/#RcptNo)[1]', 'int'),
CustName = XC.value('(KsRecord/ReceiptAmt/#CustName)[1]', 'varchar(25)'),
-- reach into the <CustomerRecord> subnode under <KitchenOrder>
CustomerLastName = xc.value('(CustomerRecord/ContactInfo/#LastName)[1]', 'varchar(50)'),
CustomerEmail = xc.value('(CustomerRecord/ContactInfo/Email/#MailTo)[1]', 'varchar(50)')
FROM
-- get a "virtual" table of XML fragments, one for each <KitchenOrder> node
#myxmlinv.nodes('/KitchenSupply/KitchenOrder') AS XT(XC)
Yes, it's the namespace. To get SQL Server to ignore the namespace you can use local-name:
SELECT *
FROM #myxmlinv_table
WHERE inv_xml.exist('//*[local-name()="KitchenSupply"]') = 1

Resources