34,576
社区成员
发帖
与我相关
我的任务
分享
declare cur cursor
for select ydh from ypls.dbo.spgj_yjm
declare @ydh int;
open cur
fetch next from cur into @ydh
while @@fetch_status = 0
begin
;with cte as(
select '00000000000000043621' as FromCorpID,getdate() as ActDate,'蔡琳' as Actor,t1.ydh as CorpOrderID,'2013'+right('0000000000'+cast(t1.ydh as varchar),10) as BillID,'102' as Name,
cast((select '' as UpperCorpOrderID,t2.yjm as Code from ypls.dbo.spgj_yjm t2 where t2.flag=0 and t1.ydh=t2.ydh for xml raw('Data')) as xml) DataField
from ypls.dbo.spgj_yjm t1
where t1.flag=0 and t1.ydh = @ydh
group by t1.ydh
)
select CorpOrderID
,cast('<Document xmlns:xsi="http://www1.drugadmin.com" Version="3.0" SN="computer" License="license">
<Event ID="StockIn">
'+
(select * from cte t2 with(nolock) where t1.CorpOrderID=t2.CorpOrderID for xml raw('Bill'))+'
</Event>
</Document>' as xml)as xmlCol
from cte t1 with(nolock)
group by CorpOrderID
fetch next from cur into @ydh
end
close cur
deallocate cur
with cte as(
select '00000000000000043621' as FromCorpID,getdate() as ActDate,'蔡琳' as Actor,t1.ydh as CorpOrderID,'2013'+right('0000000000'+cast(t1.ydh as varchar),10) as BillID,'102' as Name,
cast((select '' as UpperCorpOrderID,t2.yjm as Code from ypls.dbo.spgj_yjm t2 where t2.flag=0 and t1.ydh=t2.ydh for xml raw('Data')) as xml) DataField
from ypls.dbo.spgj_yjm t1
where t1.flag=0
group by t1.ydh
)
select CorpOrderID
,cast('<Document xmlns:xsi="http://www1.drugadmin.com" Version="3.0" SN="computer" License="license"><Event ID="StockIn">'+
(select * from cte t2 with(nolock) where t1.CorpOrderID=t2.CorpOrderID for xml raw('Bill'))+'</Event></Document>' as xml)as xmlCol
from cte t1 with(nolock)
group by CorpOrderID
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns:xsi="http://www1.drugadmin.com" Version="3.0" SN="computer" License="license">
<Event ID="StockIn">
<Bill FromCorpID="00000000000000043621" ActDate="2014-01-20T16:28:58.617" Actor="蔡琳" CorpOrderID="2995975" BillID="20130002995975" Name="102">
<DataField>
<Data UpperCorpOrderID="" Code="81206620073443503824" />
<Data UpperCorpOrderID="" Code="81206620073443470219" />
<Data UpperCorpOrderID="" Code="81206620073443499601" />
</DataField>
</Bill>
</Event>
</Document>
with cte as(
select '00000000000000043621' as FromCorpID,getdate() as ActDate,'蔡琳' as Actor,t1.ydh as CorpOrderID,'2013'+right('0000000000'+cast(t1.ydh as varchar),10) as BillID,'102' as Name,
cast((select '' as UpperCorpOrderID,t2.yjm as Code from ypls.dbo.spgj_yjm t2 where t2.flag=0 and t1.ydh=t2.ydh for xml raw('Data')) as xml) DataField
from ypls.dbo.spgj_yjm t1
where t1.flag=0
group by t1.ydh
)
select CorpOrderID
,cast('<Document xmlns:xsi="http://www1.drugadmin.com" Version="3.0" SN="computer" License="license"><Event ID="StockIn">'+
(select * from cte t2 with(nolock) where t1.CorpOrderID=t2.CorpOrderID for xml raw('Bill'))+'</Event></Document>' as xml)as xmlCol
from cte t1 with(nolock)
group by CorpOrderID
create table spgj_yjm(ydh int,yjm varchar(20),flag int)
insert into spgj_yjm(ydh,yjm,flag)
select 2986257, '81053100420710742042', 0 union all
select 2986257, '81053100345474414914', 0 union all
select 2986257, '81053100345407630079', 0 union all
select 2986257, '81053100420710626059', 0 union all
select 2986257, '81053100345090719079', 0 union all
select 2986257, '81362950039343829966', 0 union all
select 2986257, '81362950039059747590', 0 union all
select 2986257, '81362950039278683351', 0 union all
select 2986257, '81362950039481176662', 0 union all
select 2986257, '81362950035147001616', 0 union all
select 2986257, '81362950034626317707', 0 union all
select 2986257, '81362950039799701376', 0 union all
select 2986257, '81362950039927332623', 0 union all
select 2986257, '81362950039893599528', 0 union all
select 2986257, '81362950039113920380', 0 union all
select 2986257, '81476910211407935898', 0 union all
select 2986257, '81476910211407935898', 0 union all
select 2986257, '81476910097890889250', 0 union all
select 2986257, '81419670574806084646', 0 union all
select 2986257, '81419670570800837414', 0 union all
select 2986257, '81419670576219782529', 0 union all
select 2986257, '81419670572037813949', 0 union all
select 2986257, '81419670568375687887', 0 union all
select 2995975, '81206620073443503824', 0 union all
select 2995975, '81206620073443470219', 0 union all
select 2995975, '81206620073443499601', 0 union all
select 2995974, '81311630034496251611', 0 union all
select 2995974, '81311630034496822406', 0 union all
select 2995974, '81311630034496872428', 0 union all
select 2995974, '81311630034496797857', 0 union all
select 2995974, '81311630034677491438', 0 union all
select 2995974, '81311630034496802588', 0 union all
select 2995974, '81311630034496812356', 0 union all
select 2995974, '81311630034680372827', 0 union all
select 2995974, '81311630034496850861', 0 union all
select 2995974, '81311630034496861165', 0 union all
select 2995974, '81311630034677480463', 0 union all
select 2995974, '81311630034680390993', 0 union all
select 2995974, '81605280127535045624', 0 union all
select 2995974, '81605280127463070629', 0 union all
select 2995974, '81605280127537065416', 0 union all
select 2995974, '81605280127464511002', 0 union all
select 2995974, '81605280127428491931', 0 union all
select 2995974, '81605280127465590151', 0 union all
select 2995974, '81605280127464871653', 0 union all
select 2995974, '81605280127535221920', 0 union all
select 2995974, '81605280127427235970', 0 union all
select 2995974, '81605280127472761856', 0 union all
select 2995974, '81605280127460732584', 0 union all
select 2995974, '81605280127463791356', 0 union all
select 2995974, '81605280127426874334', 0 union all
select 2995974, '81605280127463254606', 0 union all
select 2995974, '81605280127535940173', 0 union all
select 2995974, '81605280127539541185', 0 union all
select 2995974, '81605280127463619787', 0 union all
select 2995974, '81605280127464159628', 0 union all
select 2995974, '81605280127536485123', 0 union all
select 2995974, '81605280127461276246', 0 union all
select 2995974, '81605280127463431091', 0 union all
select 2995974, '81605280127533967268', 0 union all
select 2995974, '81605280127533428059', 0 union all
select 2995974, '81605280127534147380', 0 union all
select 2995974, '81605280127539002267', 0 union all
select 2995974, '81605280127534506824', 0 union all
select 2995974, '81605280127427956164', 0 union all
select 2995974, '81605280127472581208', 0 union all
select 2995974, '81605280127537607374', 0 union all
select 2995974, '81605280127427419772', 0 union all
select 2995974, '81605280127428315154', 0 union all
select 2995974, '81605280127345877748', 0 union all
select 2995974, '81605280127171837163', 0 union all
select 2995974, '81605280127426338395', 0 union all
select 2995974, '81605280127460913138', 0 union all
select 2995974, '81605280127461452218', 0 union all
select 2995974, '81605280127539901726', 0 union all
select 2995974, '81605280127465415833', 0 union all
select 2995974, '81605280127534323242', 0 union all
select 2995974, '81605280127345694603', 0 union all
select 2995974, '81605280127537962717', 0 union all
select 2995974, '81605280127427591245', 0 union all
select 2995974, '81605280127536307424', 0 union all
select 2995974, '81605280127536883412', 0 union all
select 2995974, '81605280127539182095', 0 union all
select 2995974, '81605280127536666302', 0 union all
select 2995974, '81605280127462178238', 0 union all
select 2995974, '81605280127462530869', 0 union all
select 2995974, '81419670566978456179', 0 union all
select 2995974, '81419670567631216369', 0 union all
select 2995974, '81419670566871919395', 0 union all
select 2995974, '81419670568193533020', 0 union all
select 2995974, '81419670575311965521', 0 union all
select 2995974, '81419670574718171679', 0 union all
select 2995974, '81419670571761932295', 0 union all
select 2995974, '81419670573716174759', 0 union all
select 2995974, '81419670575655744424', 0 union all
select 2995974, '81419670568116444607', 0 union all
select 2995974, '81419670568767948620', 0 union all
select 2995974, '81419670567897893551', 0 union all
select 2995974, '81419670571439491486', 0 union all
select 2995974, '81419670575798074186', 0 union all
select 2995974, '81419670568465864814', 0 union all
select 2995974, '81419670571664371678', 0 union all
select 2995974, '81419670568441494203', 0 union all
select 2995974, '81419670573703222174', 0 union all
select 2995974, '81419670574988061189', 0 union all
select 2995974, '81419670569002206091', 0 union all
select 2995974, '81419670573044551941', 0 union all
select 2995974, '81419670567728585350', 0 union all
select 2995974, '81419670571035640105', 0 union all
select 2995974, '81419670576664810900', 0 union all
select 2995974, '81419670571430405293', 0 union all
select 2995974, '81419670575869087500', 0 union all
select 2995974, '81419670575890331625', 0 union all
select 2995974, '81419670569459520874', 0 union all
select 2995974, '81419670573709024618', 0 union all
select 2995974, '81419670575417342131', 0 union all
select 2995974, '81419670567622964203', 0 union all
select 2995974, '81419670572626956687', 0 union all
select 2995974, '81419670576195772019', 0 union all
select 2995974, '81419670570198750013', 0 union all
select 2995974, '81419670572037764667', 0 union all
select 2995974, '81419670575512527854', 0 union all
select 2995974, '81419670568452785190', 0 union all
select 2995974, '81419670571251144848', 0 union all
select 2995974, '81419670575235764766', 0 union all
select 2995974, '81419670573052548380', 0 union all
select 2995974, '81419670569919678375', 0 union all
select 2995974, '81419670575401066878', 0 union all
select 2995974, '81419670575600895598', 0 union all
select 2995974, '81419670567636271195', 0 union all
select 2995974, '81419670574019496739', 0 union all
select 2995974, '81419670576512854067', 0 union all
select 2995974, '81419670569003494117', 0 union all
select 2995974, '81419670575407245797', 0 union all
select 2995974, '81419670570953474751', 0 union all
select 2995974, '81419670573759059428', 0 union all
select 2995974, '81419670567415872945', 0 union all
select 2995974, '81419670567116101057', 0 union all
select 2995974, '81419670571853684739', 0 union all
select 2995974, '81419670574381862922', 0 union all
select 2995974, '81419670568856792181', 0 union all
select 2995974, '81419670574714324029', 0 union all
select 2995974, '81419670571421884259', 0 union all
select 2995974, '81419670574247712559', 0 union all
select 2995974, '81419670575599350781', 0 union all
select 2995974, '81419670574748899490', 0 union all
select 2995974, '81419670575629222128', 0 union all
select 2995974, '81419670567489351145', 0 union all
select 2995974, '81419670575596257502', 0 union all
select 2995974, '81419670572077624268', 0