改成这样试试:declare @maxnum int; declare @danjutou varchar(10); declare @maxdanju varchar(20); BEGIN TRANSACTION Begin /* select @maxnum=maxnum from a where id=112; ----标志1 select @danjutou=danjutou from b where id=888; set @maxdanju=@danjutou+@maxnum; */ update a set maxnum=(select maxnum from a where id=112)+1 where id=112; ---标志2 update c set fnumber=(select maxnum from a where id=112)+ (select danjutou from b where id=888) where id=***; End commit TRANSACTION
哦,试试这个,加了updlock,也就是更新锁: declare @maxnum int; declare @danjutou varchar(10); declare @maxdanju varchar(20); BEGIN TRANSACTION Begin select @maxnum=maxnum from a with(xlock) where id=112; ----标志1 select @danjutou=danjutou from b with(xlock) where id=888; set @maxdanju=@danjutou+@maxnum; update a set maxnum=@maxnum+1 where id=112; ---标志2 update c set fnumber=@maxdanju where id=***; End commit TRANSACTION
declare @danjutou varchar(10);
declare @maxdanju varchar(20);
BEGIN TRANSACTION
Begin
/*
select @maxnum=maxnum from a where id=112; ----标志1
select @danjutou=danjutou from b where id=888;
set @maxdanju=@danjutou+@maxnum;
*/
update a set maxnum=(select maxnum from a where id=112)+1 where id=112; ---标志2
update c set fnumber=(select maxnum from a where id=112)+
(select danjutou from b where id=888)
where id=***;
End
commit TRANSACTION
我一直以为SQL SERVER默认的是READ COMMITTED
哦,试试这个,加了updlock,也就是更新锁:
declare @maxnum int;
declare @danjutou varchar(10);
declare @maxdanju varchar(20);
BEGIN TRANSACTION
Begin
select @maxnum=maxnum from a with(xlock) where id=112; ----标志1
select @danjutou=danjutou from b with(xlock) where id=888;
set @maxdanju=@danjutou+@maxnum;
update a set maxnum=@maxnum+1 where id=112; ---标志2
update c set fnumber=@maxdanju where id=***;
End
commit TRANSACTION
会不会是这个类型
3+5=8
4+4=8
因为你是2个参数,获取的最大值相加的结果
A表存单据类型及各单据类型(如出库单)的最大单据编号的数字部分,比如00235
B表存各单据类型最大单据的完整编号,比如TX00235
C表存单据的完整信息,如编号、部门、产品等生成编号时是先从A表取出库单类型的最大编号。并储存在临时字段中,值是TX00235
再将00235+1的值00236写回A表
再将TX00236写回B表
再将包括TX00235在内的一些信息插入到C表。