begin tran declare @rownum1 int --未添加订单的空房数 declare @rownum2 int --添加订单的空房数目 declare @BookID1 int set @BookID1=0 insert into T_BookRoomInfo(RoomID,CustomerName,CustomerCardID,Discount, EnterTime,DepositMoney,Memo,UserID,UpdTime) values (@RoomID,@CustomerName,@CustomerCardID,@Discount, getdate(),@DepositMoney,@Memo,@UserID,getdate()) select @BookID1=@@IDENTITY if(@BookID1<>0) begin select @rownum1=count(1) from T_Room where IsEmploy=0 update T_Room set IsEmploy=1 where RoomID=@RoomID select @rownum1=count(1) from T_Room where IsEmploy=0 if(@rownum1<=@rownum2) begin rollback tran end else begin commit tran end end else begin rollback tran end