我在sql2000里执行了一个存储过程,其实使用了一个临时表,但是没有删除存储过程的语句,怎么存储过程会消失了,但是在sql2005里使用就是正常的。请问这是怎么回事?我吧存储过程贴出来,请大神帮我解答。
if exists(select name from sysobjects where name='NonSaleOut'and type='p')
drop procedure NonSaleOut
go
create procedure NonSaleOut
@danh varchar(50)--单号
as
begin
declare @goods_count int--配送出库产品种类(总行数)
declare @goodsid varchar(50)--商品条码
declare @goodsname varchar(50)--商品名称
declare @kucun_count float --库存数量
declare @ps_count float --配送单某条码的数量
declare @ps_number int --配送明细单序号
declare @check int --检验数量
declare @kdbm varchar(50)--开单部门
declare @bmbm varchar(50)--开单部门代码
declare @shck varchar(50)--收货仓库
declare @ckbm varchar(50)--收货仓库代码
declare @kdsj varchar(50)--开单时间
declare @id varchar(50) --退货单id号
declare @jbr varchar(50) --经办人
declare @jine float--商品销售价
declare @remark varchar(50)--备注
declare @errno int
set @errno=0
set @check=0
set @ps_number=0--配送明细单序号,初始为0
select @goods_count=count(*) from NONSALEOUTDETAIL where danh=@danh--获取配送单商品种类数量
select @kdbm=kdbm,@bmbm=bmbm,@shck=shck,@ckbm=ckbm,@kdsj=kdsj,@jbr=jbr from NONSALEOUTDOC where danh=@danh
SELECT IDENTITY(int, 1,1) AS id,convert(int,gid)as gid,danh,goodsname,goodsid,shul,jine,remark into #nonsaleout from NONSALEOUTDETAIL where danh=@danh
Begin TransAction --事务开始
while (@ps_number<@goods_count)
begin
set @ps_number=@ps_number+1--配送明细单序号自增一
select @goodsname=goodsname,@goodsid=goodsid,@ps_count=shul,@jine=jine,@id=gid,@remark=remark from #nonsaleout where id=@ps_number--获取某条细单的商品名称,商品条码,数量
select @kucun_count=count(*) from QL_SSTORE_GOODS where goodsid=@goodsid
if (@kucun_count>0)
begin
update GOODS set stock=convert(numeric(18,2),(stock-@ps_count)) where goodsid=@goodsid
set @errno=@errno+@@error
insert into CHANGES(gsdh,goodsname,goodsid,shul,jine,kdsj,kdry,remark) select danh,goodsname,goodsid,-shul,jine,convert(varchar(20),getdate(),120),@jbr,'aa' from NONSALEOUTDETAIL where danh=@danh and goodsid=@goodsid and gid=@id
set @errno=@errno+@@error
end
else
begin
insert into GOODS(goodsname,goodsid,stock,price,clerk,inputtime)values(@goodsname,@goodsid,convert(numeric(18,2),-@ps_count),@jine,@jbr,convert(varchar(20),getdate(),120))
insert into CHANGES(gsdh,goodsname,goodsid,shul,jine,kdsj,kdry,remark) select danh,goodsname,goodsid,-shul,jine,convert(varchar(20),getdate(),120),@jbr,'aa' from NONSALEOUTDETAIL where danh=@danh and goodsid=@goodsid and gid=@id
set @errno=@errno+@@error
end
end--while循环结束
if(@ps_number=@goods_count)--判断数据是否插入完
begin
update NONSALEOUTDOC set suodsm='过账',suod='3' where danh=@danh
set @errno=@errno+@@error
set @check=0
end