sp_xml_preparedocument sp_xml_removedocument 使用 实例 解析

来源:互联网 发布:淘宝科勒马桶盖价格 编辑:程序博客网 时间:2024/05/16 12:23

--声明一个xml对象字符串

declare @studentxml as varchar(200)

--设置处理xml实例

set @studentxml=' <stus><student id="341208" value="25"></student><student id="341209" value="26"></student></stus>'

--声明@docid

declare @docid int  

exec sp_xml_preparedocument @docid output, @studentxml  

--检索相应数据保存到对应数据列中

select * into #stu_tmp 

from openxml(@docid, '/stus/student', 2)  

with  

(  

  stuid int '@id',  --声明列stuid

  stuage nvarchar(512) '@value'   --声明列stuage 

--查看处理后的数据

select * from #stu_tmp

--删除临时处理表

drop table #stu_tmp

--释放当前文档标记

exec sp_xml_removedocument @docid

--*=   就是   左连接   Left   Join

原创粉丝点击