日期:2014-05-17 浏览次数:20538 次
-- 主表 yshm.mid字段为主键
create table yshm(mid int,a varchar(10),b varchar(10),c varchar(10))
-- 明细表 yshd.mid字段对应yshm.mid字段
create table yshd(mid int,d varchar(10),e varchar(10),f varchar(10))
-- 中间表
create table xmltable(xmldata varchar(max))
insert into yshm
select 1,'a1','b1','c1' union all
select 2,'a2','b2','c2' union all
select 3,'a3','b3','c3'
insert into yshd
select 1,'d1','e1','f1' union all -- 1
select 1,'d2','e2','f2' union all
select 2,'d3','e3','f3' union all -- 2
select 3,'d4','e4','f4' union all -- 3
select 3,'d5','e5','f5'
declare @xmldata varchar(max),@mid int,@a varchar(10),@b varchar(10),@c varchar(10),@x varchar(max),@cmd varchar(8000)
select @xmldata='<?xml version="1.0" encoding="UTF-8"?>
<Document License="license" SN="computer" Version="3.0" xmlns:xsi="http://www1.drugadmin.com">
<Event ID="StockIn">'
declare ap cursor static for select mid,a,b,c from yshm
open ap
fetch first from ap into @mid,@a,@b,@c
while(@@fetch_status<>-1)
begin
select @xmldata=@xmldata
+'<Bill mid="'+rtrim(@mid)+'" cola="'+@a+'" colb="'+@b+'" colc="'+@c+'" >'
+'<DataField>',
@x=''
select @x=@x+'<Data cold="'+d+'" e="'+e+'" f="'+f+'" />'
from yshd where