如果您需要执行需要循环的 *** 作(例如,要向每个收件人发送电子邮件,则可以使用游标:
declare cur cursor local fast_forward for select s.c.value('(text())[1]', 'nvarchar(max)') as SendTo, m.c.value('(MyMsg/text())[1]', 'nvarchar(max)') as MyMsg, m.c.value('(MsgTime/text())[1]', 'nvarchar(max)') as MsgTime from @XML_In.nodes('MyXML') as m(c) outer apply m.c.nodes('SendToList/SendTo') as s(c)open curwhile 1 = 1begin fetch cur into @SendTo, @MyMsg, @MsgTime if @@fetch_status <> 0 break --======================================= -- do what you need here --=======================================endclose curdeallocate cur
如果只想将行插入到某个表中,则可以通过一个简单的插入 *** 作来完成:
insert into <Your table>( SendTo, MyMsg, MsgTime)select s.c.value('(text())[1]', 'nvarchar(max)') as SendTo, m.c.value('(MyMsg/text())[1]', 'nvarchar(max)') as MyMsg, m.c.value('(MsgTime/text())[1]', 'nvarchar(max)') as MsgTimefrom @XML_In.nodes('MyXML') as m(c) outer apply m.c.nodes('SendToList/SendTo') as s(c)
[sql fiddle demo](http://sqlfiddle.com/#!3/d41d8/21491)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)