Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL 2008, need help with XML parsing and inserting into Table

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I have this sampl XML
when I run this it shows columns and rows but the column have no names and the data in each row is null.
I am going to pass the XML string into a stored Procedure from .NET

Code:
Declare @xmlInput xml
Set @xmlInput =('<fileData>
<row>
<EID>7747379800</EID> 
<Name>Flintstone, Fred</Name> 
<Email>fred@flintstone.com</Email> 
<ManagerEID>123456</ManagerEID>
 <Manager></Manager> 
 <C>USA</C> 
 <L>My City</L>
  <SurName>Flintstone</SurName>
   <State>FL</State>
  </row>
         
         <row>
         <EID>7463614574</EID> 
         <Name>Flintstone, Wilma</Name> 
         <Email>wilma@graveltown.com</Email>
          <ManagerEID>7747379800</ManagerEID>
           <Manager>Mr Spacely</Manager>
            <C>USA</C>
             <L>MyTown</L>
              <SurName>Flinstone</SurName>
               <State>XX</State> 
      </row>

SELECT  
       T.C.value('@EID', 'nvarchar(60)'),  
       T.C.value('@Name', 'nvarchar(60)'),  
       T.C.value('@Email','nvarchar(60)'),  
       T.C.value('@ManagerEID', 'nvarchar(60)'),  
       T.C.value('@Manager', 'nvarchar(60)'),  
       T.C.value('@C', 'nvarchar(60)'),  
       T.C.value('@L', 'nvarchar(60)'),  
       T.C.value('@Surname', 'nvarchar(60)'),  
       T.C.value('@State', 'nvarchar(60)'),  
FROM @xmlInput.nodes('//row') T(C)

DougP
 
OK, got it works !!!!
I changed each line to

T.C.value('[highlight #FCE94F].[1]/[/highlight]EID[highlight #FCE94F][1]/.[/highlight]', 'nvarchar(60)') [highlight #FCE94F]as EID[/highlight] ,

DougP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top