Please help with XML query -
03-24-2010
, 02:37 PM
THANK YOU FOR YOUR HELP.
--From this XML
declare @xml xml = '<root>
<Identity docID="F230D2AA-BD00-4B68-BDDC-394F900AE583" CreatedOn="2010-03-24T15:26:16.817Z" CreatedUsername="vladimir" SourceComputer="???" SourceApplication="Microsoft SQL Server Management Studio - Query" Version="4.3.0">
<Config AutoImport="false" Action="ADD" />
</Identity>
<Organizations>
<Organization OrganizationCode="AM " Name="Alfred Williams, Inc. []" Website="www.alfredwilliams.com" Type="C" Info1="Dealer" CurrencyCode="USD" TaxCode="Apex" PaymentTermsCode="Net 30" CreditHold="false" Effective="1990-01-01Z" Inactive="2050-12-31Z" CreditLimit="100000" OpenReceivables="1000" CreditTolerancePercent="3" RequireDeposit="1" RequiredDepositPercent="3" TaxCategoryCode="Retailer">
<Attribute AttributeCode="Sales Region" Value="East" />
<Address Type="SHIP" LocationCode="CA" LocationName="Bruce Smith" Address1="102 Glen Cairn Court" City="Apex" State="nc " Zip="27502" Country="US" Phone="919-380-1010" Fax="919-019-1919" IsDefault="1" Effective="1990-01-01Z" Inactive="2050-12-31Z" Language="English" ShipmentModeCode="FT" ShipInstructions="Deliver to rear entrance" CarrierCode="YLW" FreightTermsCode="2" ShippingZoneCode="SE" TaxCode="Apex" />
<Address Type="BILL" LocationCode="st" LocationName="Alfred Williams" Address1="4839 New Bern Ave." City="Raleigh" State="NC " Zip="27607" Country="US" Phone="919-392-9555" Fax="919-392-4839" IsDefault="1" Effective="1990-01-01Z" Inactive="2050-12-31Z" Language="English" TaxCode="Apex" />
<Address Type="BILL" LocationCode="stVlad2" LocationName="Alfred Williams" Address1="4839 New Bern Ave." City="Raleigh" State="NC " Zip="27607" Country="US" Phone="919-392-9555" Fax="919-392-4839" IsDefault="0" Effective="1990-01-01Z" Inactive="2050-12-31Z" Language="English" TaxCode="Apex" />
<Address Type="MAIL" LocationCode="BS" LocationName="Bruce Smith" Address1="102 Glen Cairn Court" City="Apex" State="NC " Zip="27502" Country="US" Phone="919-380-1010" Fax="919-019-1919" IsDefault="0" Effective="1900-01-01Z" Inactive="2079-06-06Z" Language="English" TaxCode="Apex" />
</Organization>
</Organizations>
</root>'
--How do I query this xml to produce one below
--root/Organizations/Organization/Address[@Type="BILL" and @IsDefault="1" or @Type="SHIP" and @IsDefault="1"]
select @xml.query('root/Organizations/Organization/Address[@Type="BILL" and @IsDefault="1" or @Type="SHIP" and @IsDefault="1"]')
-- This is what I need.
/*
<Organization OrganizationCode="AM " Name="Alfred Williams, Inc. []" Website="www.alfredwilliams.com" Type="C" Info1="Dealer" CurrencyCode="USD" TaxCode="Apex" PaymentTermsCode="Net 30" CreditHold="false" Effective="1990-01-01Z" Inactive="2050-12-31Z" CreditLimit="100000" OpenReceivables="1000" CreditTolerancePercent="3" RequireDeposit="1" RequiredDepositPercent="3" TaxCategoryCode="Retailer">
<Attribute AttributeCode="Sales Region" Value="East" />
<Address Type="SHIP" LocationCode="CA" LocationName="Bruce Smith" Address1="102 Glen Cairn Court" City="Apex" State="nc " Zip="27502" Country="US" Phone="919-380-1010" Fax="919-019-1919" IsDefault="1" Effective="1990-01-01Z" Inactive="2050-12-31Z" Language="English" ShipmentModeCode="FT" ShipInstructions="Deliver to rear entrance" CarrierCode="YLW" FreightTermsCode="2" ShippingZoneCode="SE" TaxCode="Apex" />
<Address Type="BILL" LocationCode="st" LocationName="Alfred Williams" Address1="4839 New Bern Ave." City="Raleigh" State="NC " Zip="27607" Country="US" Phone="919-392-9555" Fax="919-392-4839" IsDefault="1" Effective="1990-01-01Z" Inactive="2050-12-31Z" Language="English" TaxCode="Apex" />
</Organization>
*/ |