Advertisement
Guest User

SweNz

a guest
Aug 25th, 2015
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.07 KB | None | 0 0
  1. create TABLE CustomerInfo
  2. ( data XML);
  3.  
  4. -------------------------------
  5.  
  6. insert INTO CustomerInfo
  7.         ( data )
  8. VALUES  ( CAST('<ArrayOfCustomerInfo  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
  9.  <Customer CustCode="001">
  10.    <CustName>John</CustName>
  11.    <Queues>
  12.      <Q>
  13.        <No>3</No>
  14.         <Line>1</Line>
  15.      </Q>
  16.    </Queues>
  17.  </Customer>
  18.  <Customer CustCode="035">
  19.    <CustName>Chris</CustName>
  20.    <Queues>
  21.      <Q>
  22.        <No>10</No>
  23.         <Line>1</Line>
  24.      </Q>
  25.    </Queues>
  26.  </Customer>
  27.  </ArrayOfCustomerInfo>' AS XML)
  28.           );
  29.  
  30. --------------------------------------------------------------------------------------------------
  31.  
  32. SELECT a.b.value('@CustCode','varchar(4)') AS Code
  33.        ,a.b.value('CustName[1]','varchar(20)') AS Name
  34.        ,c.d.value('No[1]','int') AS QNo
  35.        ,c.d.value('(Line)[1]','int') AS QLine
  36. FROM  PGHRMS_Employees x
  37. CROSS APPLY x.data.nodes('/ArrayOfCustomerInfo/Customer') AS a(b)
  38. CROSS APPLY a.b.nodes('Queues/Q') AS c(d)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement