dbTalk Databases Forums  

Please help with XML query

microsoft.public.sqlserver.xml microsoft.public.sqlserver.xml


Discuss Please help with XML query in the microsoft.public.sqlserver.xml forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Farmer
 
Posts: n/a

Default 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>

*/

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.