Deserialize XML object in T-SQL

前端 未结 1 566
梦谈多话
梦谈多话 2020-12-17 03:53

I\'ve got an XML object. And I want to deserialize it into a table using T-SQL.


    

        
1条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-17 04:02

    Your XML is not valid - but if you had something like this:

    
         
             10 
        
         
             abc 
        
    
    

    then you could use this XQuery / SQL statement to get what you're looking for:

    DECLARE @XML XML = '
         
             10 
        
         
             abc 
        
    '
    
    SELECT
        Type = TypeNode.value('@ID', 'int'),
        NodeValue = TypeNode.value('(value)[1]', 'varchar(50)')
    FROM
        @XML.nodes('/Params/type') AS XTbl(TypeNode)
    

    I'm not clear how/what the id column is supposed to be - care to explain?

    0 讨论(0)
提交回复
热议问题