--声明一个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