alter proc songhaitao
@UserID varchar(100),
@Items varhcar(2000),
@OpCode int,
@Root=''
as
begin
set nocount on
declare @hdoc varchar(1000)
declare @ret int
declare @retmsg varchar(2000)
exec @ret=sp_xml_preparedocument @hdoc output,@Root
if @ret!=1
begin
set @ret=-1234
set @retmsg='读取 xml文件失败'
goto outcode
end
select *
into #VItems
from openxml(@hdoc,@Root,1)
with(
DATAKEY INT,
GAGOODSID INT,
GAPROVIDER VARCHAR(50),
GACUSTOMER VARCHAR(100),
[STATE] INT
)
if @@rowcount<=0
begin
set @ret=-1332
set @retmsg='没有处理的信息'
goto outcode
end
if @OpCode in(1,2)
begin
if exit(select * from #VItems where GAGOODSID is null or GAGOODSID=''
or GAPROVIDER is null or GAPROVIDER=''
or GACUSTOMER is null or GACUSTOMER=''
)
begin
set @ret=-6579
set @retmsg='输入信息不能为空'
goto outcode
end
end
if @OpCode=1
begin
if exit(select * from #VItems where DATAKEY=0)
begin
declare @mid int
select @mid=max(GAID) from DPV_GOODSADJUST where 1=1
select identity(int,1,1) as rid,*
into #IVtems
from #VItems
insert DPV_GOODSADJUST(GAGOODSID,GAPROVIDER,GACUSTOMER,[STATE])
select @mid+rid,GAprovider,GACustomer,[State]
from #IVtems
if @@error<>0
begin
rollback tran
set @ret=-4323
set @retmsg='插入失败'
goto outcode
end
end
end
if @OpCode=2
begin
if exit(select * from #VItems where DATAKEY<>0)
begin
update a set
GAGOODSID=b.GAGOODSID,
GAPROVIDER=b.GAPROVIDER,
GACUSTOMER=b.GACUSTOMER,
[STATE]=b.[STATE]
from DPV_GOODSADJUST a,#Vitems b
where a.GAID=b.DATAKEY
if @@error<>0
begin
rollback tran
set @ret=-1342
set @retmsg='修改失败'
goto outcode
end
end
end
if @OpCode=3
begin
if exit(select * from #VItems where DATAKEY<>0)
begin
delete from #VItems b,DPV_GOODSADJUST a
where a.GAID=b.DATAKEY
if @@error<>0
begin
rollback tran
set @ret=-1342
set @retmsg='删除失败'
goto outcode
end
end
end
outcode:
exec sp_xml_removedocument @hdoc
select @ret, @retmsg
return @ret
END
转载于:https://www.cnblogs.com/qingtaong/archive/2012/06/29/2569909.html