x

XML output for same child node

Hi All,

I have written below qry

   select  (SELECT value 
             FROM
          TmsConfiguration where keyname='ShipmentCreate_ContainerTypeCode'  
  )AS ContainerTypeCode ,
 
         Quantity    ,
         Length    ,
         Width    ,
         Height  ,
         ScaledWeight as [ContainerShippingInformation/ScaledWeight],
         Volume as [ContainerShippingInformation/Volume] ,
         NominalWeight as [ContainerShippingInformation/NominalWeight] ,
         Pieces  as [ContainerShippingInformation/Pieces],
         ContainerDescription ,                                 
         (select value  from
    TmsConfiguration where keyname='ShipmentCreate_IgnoreContainerOrientationsFlag')  
    as [IgnoreContainerOrientationsFlag],
    (SELECT VALUE   
  FROM TmsConfiguration where keyname='ShipmentCreate_IgnoreWeightByFreightClassFlag')
  as [IgnoreWeightByFreightClassFlag], 
  --FreightClassNominalWeight  as [WeightByFreightClass/FreightClassNominalWeight],
  FreightClassCode as [WeightByFreightClass/FreightClassCode],
  (SELECT VALUE 
  FROM TmsConfiguration where keyname='ShipmentCreate_IgnoreShipmentItemsFlag')
  as [IgnoreShipmentItemsFlag],
  (SELECT VALUE  
  FROM TmsConfiguration where keyname='ShipmentCreate_IgnoreReferenceNumbersFlag')
  as [IgnoreReferenceNumbersFlag],
  
  (SELECT value  FROM
            TmsConfiguration where keyname='ShipmentCreate_ReferenceNumberTypeCode_7')
  as [ReferenceNumberStructure/ReferenceNumberTYPECode],
        
  ReferenceNumber7 as [ReferenceNumberStructure/ReferenceNumber]
   
   ,
     (SELECT value  FROM
            TmsConfiguration where keyname='ShipmentCreate_ReferenceNumberTypeCode_8')
   as [ReferenceNumberStructure/ReferenceNumberTYPECode],
  
  ReferenceNumber8 as [ReferenceNumberStructure/ReferenceNumber]
  
         
   from #ShipmentCreate
    for xml path('Container')


Out put of above is

Pieces 2 0 0 0

 <ScaledWeight>0</ScaledWeight>
 <Volume>0</Volume>
 <NominalWeight>0</NominalWeight>
 <Pieces>2</Pieces>
  

Classic Matt Twin True False True False

 <ReferenceNumberTYPECode>T_IID</ReferenceNumberTYPECode>
 <ReferenceNumber>1605</ReferenceNumber>
 <ReferenceNumberTYPECode>T_COM</ReferenceNumberTYPECode>
 <ReferenceNumber>440</ReferenceNumber>
  


Pieces 3 0 0 0

 <ScaledWeight>0</ScaledWeight>
 <Volume>0</Volume>
 <NominalWeight>0</NominalWeight>
 <Pieces>3</Pieces>
  

Classic Matt Twin True False True False

 <ReferenceNumberTYPECode>T_IID</ReferenceNumberTYPECode>
 <ReferenceNumber>1601</ReferenceNumber>
 <ReferenceNumberTYPECode>T_COM</ReferenceNumberTYPECode>
 <ReferenceNumber>440</ReferenceNumber>
  



  

but i want as

Pieces 2 0 0 0

 <ScaledWeight>0</ScaledWeight>
 <Volume>0</Volume>
 <NominalWeight>0</NominalWeight>
 <Pieces>2</Pieces>
  

Classic Matt Twin True False True False

 <ReferenceNumberTYPECode>T_IID</ReferenceNumberTYPECode>
 <ReferenceNumber>1605</ReferenceNumber>
 <ReferenceNumberTYPECode>T_COM</ReferenceNumberTYPECode>
 <ReferenceNumber>440</ReferenceNumber>
  


Pieces 3 0 0 0

 <ScaledWeight>0</ScaledWeight>
 <Volume>0</Volume>
 <NominalWeight>0</NominalWeight>
 <Pieces>3</Pieces>
  

Classic Matt Twin True False True False

 <ReferenceNumberTYPECode>T_IID</ReferenceNumberTYPECode>
 <ReferenceNumber>1601</ReferenceNumber>
  
  
 <ReferenceNumberTYPECode>T_COM</ReferenceNumberTYPECode>
 <ReferenceNumber>440</ReferenceNumber>
  


In Short my qry shows output as

 <ReferenceNumberTYPECode>T_IID</ReferenceNumberTYPECode>
 <ReferenceNumber>1605</ReferenceNumber>
 <ReferenceNumberTYPECode>T_COM</ReferenceNumberTYPECode>
 <ReferenceNumber>440</ReferenceNumber>
  

I am generating tag for item detail kind of information.I want seprate node for ReferenceNumberStructure but since this name is same for below node as well hence sql treating as single node only.

I need output as below

 <ReferenceNumberTYPECode>T_IID</ReferenceNumberTYPECode>
 <ReferenceNumber>1601</ReferenceNumber>
  
  
 <ReferenceNumberTYPECode>T_COM</ReferenceNumberTYPECode>
 <ReferenceNumber>440</ReferenceNumber>
  


more ▼

asked Sep 17, 2012 at 10:22 AM in Default

avatar image

gauravprofile
1 1 1 2

(comments are locked)
10|1200 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1069
x189

asked: Sep 17, 2012 at 10:22 AM

Seen: 3371 times

Last Updated: May 17, 2013 at 02:04 AM

Copyright 2016 Redgate Software. Privacy Policy