首页 新闻 会员 周边 捐助

sql xml

0
悬赏园豆:10 [已关闭问题] 关闭于 2013-12-23 17:23


DECLARE @idoc int
DECLARE @xmlstr nvarchar(max)=
'<root>
<row date="2013/12/1 00:00:00" model="Q201M" station="Z2" line="L1" shift="D" wo="1012" output="180" defect="65" defectcause="功能*35外觀*30"></row>
<row date="2013/12/1 00:00:00" model="Q301M" station="Z3" line="L1" shift="D" wo="1013" output="200" defect="72" defectcause="功能*30外觀*29"></row>
<row date="2013/12/1 00:00:00" model="Q401M" station="Z4" line="L1" shift="D" wo="1014" output="220" defect="79" defectcause="功能*35外觀*31"></row>
<row date="2013/12/1 00:00:00" model="Q102M" station="Z5" line="L1" shift="D" wo="1015" output="240" defect="86" defectcause="功能*30外觀*30"></row>
<row date="2013/12/1 00:00:00" model="Q202M" station="Z6" line="L1" shift="D" wo="1016" output="260" defect="93" defectcause="功能*35外觀*32"></row>
<row date="2013/12/1 00:00:00" model="Q302M" station="Z7" line="L1" shift="D" wo="1017" output="280" defect="100" defectcause="功能*30外觀*31"></row>
<row date="2013/12/1 00:00:00" model="Q402M" station="Z1" line="L2" shift="D" wo="1018" output="300" defect="107" defectcause="功能*35外觀*33"></row>
<row date="2013/12/1 00:00:00" model="Q103M" station="Z2" line="L2" shift="D" wo="1019" output="320" defect="114" defectcause="功能*30外觀*32"></row>
<row date="2013/12/1 00:00:00" model="Q203M" station="Z3" line="L2" shift="D" wo="1020" output="340" defect="121" defectcause="功能*35外觀*34"></row>
<row date="2013/12/1 00:00:00" model="Q303M" station="Z4" line="L2" shift="D" wo="1021" output="360" defect="128" defectcause="功能*30外觀*33"></row>
<row date="2013/12/1 00:00:00" model="Q403M" station="Z5" line="L2" shift="D" wo="1022" output="380" defect="135" defectcause="功能*35外觀*35"></row>
<row date="2013/12/1 00:00:00" model="Q104M" station="Z6" line="L2" shift="D" wo="1023" output="400" defect="142" defectcause="功能*30外觀*34"></row>
<row date="2013/12/1 00:00:00" model="Q204M" station="Z7" line="L2" shift="D" wo="1024" output="420" defect="149" defectcause="功能*35外觀*36"></row>
<row date="2013/12/1 00:00:00" model="Q304M" station="Z8" line="L2" shift="D" wo="1025" output="440" defect="156" defectcause="功能*30外觀*35"></row>
<row date="2013/12/1 00:00:00" model="Q404M" station="Z1" line="L3" shift="D" wo="1026" output="460" defect="163" defectcause="功能*35外觀*37"></row>
<row date="2013/12/1 00:00:00" model="Q105M" station="Z2" line="L3" shift="D" wo="1027" output="480" defect="170" defectcause="功能*30外觀*36"></row>
<row date="2013/12/1 00:00:00" model="Q205M" station="Z3" line="L3" shift="D" wo="1028" output="500" defect="177" defectcause="功能*35外觀*38"></row>
<row date="2013/12/1 00:00:00" model="Q305M" station="Z4" line="L3" shift="D" wo="1029" output="520" defect="184" defectcause="功能*30外觀*37"></row>
<row date="2013/12/1 00:00:00" model="Q405M" station="Z5" line="L3" shift="D" wo="1030" output="540" defect="191" defectcause="功能*35外觀*39"></row>
<row date="2013/12/1 00:00:00" model="Q106M" station="Z6" line="L3" shift="D" wo="1031" output="560" defect="198" defectcause="功能*30外觀*38"></row>
<row date="2013/12/1 00:00:00" model="Q206M" station="Z7" line="L3" shift="D" wo="1032" output="580" defect="205" defectcause="功能*35外觀*40"></row>
</root>'


EXEC sp_xml_preparedocument @idoc OUTPUT,
@xmlstr -- Execute a SELECT statement that uses the OPENXML rowset provider.
SELECT *
FROM OPENXML(@idoc, '/root/row', 1)
WITH (DATE nvarchar(50),
model nvarchar(50),
Station nvarchar(50),
Line nvarchar(20),
Shift varchar(10),
WO nvarchar(50),
output nvarchar(50),
Defect nvarchar(50),
defectcause nvarchar(200)

)

 

 

按以上代碼,解析完XML字段后為什么會有部分欄位為NULL值

wanghongxing的主页 wanghongxing | 初学一级 | 园豆:12
提问于:2013-12-23 17:06
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册