A
aifafa
Unregistered / Unconfirmed
GUEST, unregistred user!
create procedure proc_jifensc_5
@kkhcode char(10)
@jifen decimal(9,2)
@beizhu char(20)
AS
BEGIN
/*删除超过六个月的记录*/
if exists(select * from jifensc where riqi<convert(char(10),dateadd(month,-6,getdate()),120))/*检测有没有在六个月之外的记录*/
begin
begin tran
delete jifensc where riqi<convert(char(10),dateadd(month,-6,getdate()),120) /*删除超过六个月的记录*/
if @@error<>0
begin
rollback tran
print('删除数据库内容失败,请联系开发人员!')
return
end
else
commit tran
end
/*增加记录*/
begin tran
insert into jifensc (kkhcode,riqi,jifen,beizhu) values (@kkhcode,convert(char(10),getdate(),120),@jifen,@beizhu)
insert into jifensc (kkhcode,riqi,jifen,beizhu) values (@kkhcode,convert(char(10),getdate(),120),@jifen,@beizhu)
if @@error<>0
begin
rollback tran
print('向数据库增加记录失败,请联系开发人员!')
return
end
else
commit tran
/*更新会员档案表*/
begin tran
update cardcust set leijijf=c.jifen from cardcust a,(select kkhcode,sum(jifen)as jifen from jifensc group by kkhcode) c where a.kkhcode=c.kkhcode and a.kkhcode=@kkhcode
if @@error<>0
begin
rollback tran
print('更新数据库会员表失败,请联系开发人员!')
return
end
else
commit tran
/*列出会员积分内容*/
select a.kkhcode,a.kkhname,sum(b.jifen) as jifen,sum(b.jifen)*10 as jine from cardcust a,jifensc b where a.kkhcode=b.kkhcode and a.kkhcode=@kkhcode and b.riqi>=convert(char(10),dateadd(month,-6,getdate()),120) group by a.kkhcode,a.kkhname
return
END
其实我也知道我的事务管理太罗嗦了,可是我怕去掉其中的事务就起不到事务管理的要求,各位大哥帮我优化下!
@kkhcode char(10)
@jifen decimal(9,2)
@beizhu char(20)
AS
BEGIN
/*删除超过六个月的记录*/
if exists(select * from jifensc where riqi<convert(char(10),dateadd(month,-6,getdate()),120))/*检测有没有在六个月之外的记录*/
begin
begin tran
delete jifensc where riqi<convert(char(10),dateadd(month,-6,getdate()),120) /*删除超过六个月的记录*/
if @@error<>0
begin
rollback tran
print('删除数据库内容失败,请联系开发人员!')
return
end
else
commit tran
end
/*增加记录*/
begin tran
insert into jifensc (kkhcode,riqi,jifen,beizhu) values (@kkhcode,convert(char(10),getdate(),120),@jifen,@beizhu)
insert into jifensc (kkhcode,riqi,jifen,beizhu) values (@kkhcode,convert(char(10),getdate(),120),@jifen,@beizhu)
if @@error<>0
begin
rollback tran
print('向数据库增加记录失败,请联系开发人员!')
return
end
else
commit tran
/*更新会员档案表*/
begin tran
update cardcust set leijijf=c.jifen from cardcust a,(select kkhcode,sum(jifen)as jifen from jifensc group by kkhcode) c where a.kkhcode=c.kkhcode and a.kkhcode=@kkhcode
if @@error<>0
begin
rollback tran
print('更新数据库会员表失败,请联系开发人员!')
return
end
else
commit tran
/*列出会员积分内容*/
select a.kkhcode,a.kkhname,sum(b.jifen) as jifen,sum(b.jifen)*10 as jine from cardcust a,jifensc b where a.kkhcode=b.kkhcode and a.kkhcode=@kkhcode and b.riqi>=convert(char(10),dateadd(month,-6,getdate()),120) group by a.kkhcode,a.kkhname
return
END
其实我也知道我的事务管理太罗嗦了,可是我怕去掉其中的事务就起不到事务管理的要求,各位大哥帮我优化下!