34,590
社区成员
发帖
与我相关
我的任务
分享
CREATE PROCEDURE insertA
@mm numeric(18,2),@custname varchar(30)
AS
declare @lm as numeric(18,2)
set @lm=0
begin tran
if exists(select * from tb1 where custname=@custname)
begin
select @lm=当前金额 from tb1 with(updlock,rowlock) where id=(select max(id) from tb1 where custname=@custname)
select @lm=@lm+@mm
end
else
select @lm=@mm
insert into tb1(custname,充值金额,当前金额,systemtime)
values(@custname,@mm,@lm,getdate())
if @@error=0
commit tran
else
rollback tran
GO
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SELECT * FROM table ROWLOCK WHERE id = 1
SELECT * FROM table WITH (HOLDLOCK)
insert into tb1(custname,充值金额,当前金额,systemtime)
select top (1) @custname, @mm, 当前金额+@mm, getdate()
from (select id, 当前金额 from tb1 where custname=@custname union all select 0, 0) a
order by id desc