AS
create table #t
(
errno int,
errdesc varchar(100)
)
if @itype!=1 and @itype!=-1
begin
insert into #t values(1,'类型值错误')
end
else
begin
if @qua<=0
begin
insert into #t values(2,'数量值小于等于0')
end
else
begin
select * from t_goods where [id]= @gid
if @@ROWCOUNT>0
begin
BEGIN TRANSACTION
insert into t_inout values(@itype,@gid,@qua)
select * from t_stock where gid= @gid
if @@ROWCOUNT>0
update t_stock set quantity=quantity+@itype*@qua where gid=@gid
else
insert into t_stock(gid,quantity)values(@gid,@itype*@qua)
COMMIT TRANSACTION
insert into #t values(0,'处理完成')
end
else
BEGIN
insert into #t values(3,'商品不存在')
END
end
end
select errno,errdesc from #t
drop table #t
GO
返回的不是最后的那个。
AS
if @itype!=1 and @itype!=-1
begin
select 1,"类型值错误" --只能是 1 或 -1
return
end
if @qua<=0
begin
select 2,"数量值小于等于0"
return
end
select * from t_goods where [id]= @gid
if @@ROWCOUNT>0
begin
BEGIN TRANSACTION
insert into t_inout values(@itype,@gid,@qua)
end
else
BEGIN
select 3,"商品不存在"
return
END
select * from t_stock where gid= @gid
if @@ROWCOUNT>0
update t_stock set quantity=quantity+@itype*@qua where gid=@gid
else
insert into t_stock(gid,quantity)values(@gid,@itype*@qua)