How to Insert xml data into SQL Server table?

前端 未结 2 1166
[愿得一人]
[愿得一人] 2020-12-28 17:01

How to import below XML data into SQL Server table with three columns?

 
 
  

        
2条回答
  •  隐瞒了意图╮
    2020-12-28 17:28

    Try this:

    DECLARE @input XML = ' 
     
       
       
      
     
    
    
     SMITH 
     MARY 
     N 
    
    
     SMITH2 
     MARY2 
     N2 
    
    
    '
    
    INSERT INTO dbo.YourTable(ColName, ColFirstName, ColOther)
       SELECT
          Name = XCol.value('(value)[1]','varchar(25)'),
          FirstName = XCol.value('(value)[2]','varchar(25)'),
          OtherValue = XCol.value('(value)[3]','varchar(25)')
       FROM 
          @input.nodes('/dataset/data/row') AS XTbl(XCol)
    

提交回复
热议问题