Stored Procedures
Not practical, the reason to write, one for the leadership of the requirements, but also familiar with the writing code, the code to write more points and no harm, and wrote after the discovery of temporary table is very easy to use, the small amount of data, and do not show the speed of the temporary table is not a problem.
The code is as follows:
SET QUOTED_IDENTIFIER ON
Go
SET ANSI_NULLS on
Go
/*
Name: Four-person data in the game is updated simultaneously
Designed BY:WHBO
Designed at:2005-10-12
Modified by:
Modified at:
Memo:
*/
alter PROC [PRMONEY_UPDATECASH2]
@chvModeName varchar,
@chvSourceName varchar (),
@ Chvremark varchar (128),
@intUserID1 int,
@intUserID2 int,
@intUserID3 int,
@intUserID4 int,
@ intWantedAmount1 int,
@intWantedAmount2 int,
@intWantedAmount3 int,
@intWantedAmount4 int,
@ ChvIPAddress1 varchar,
@chvIPAddress2 varchar,
@chvIPAddress3 varchar,
@chvIPAddress4 varchar (a),
@inyLog tinyint
as
set NOCOUNT on
set xact_abort on
Declare @intCashAmount1 int, @intCashAmount2 int, @intCashAmount3 int, @intCashAmount4 int
Declare @FRate float, @FTemp float
Declare @bNeedReCalc bit --0 : Do not need to be counted; 1: The
Set @FRate =1.0
Set @FTemp =1.0
Set @bNeedReCalc =0
Declare @FTemp1 float, @FTemp2 float,@ FTemp3 float, @FTemp4 float
--Note that updating the user's cash to get the data in the database is consistent with the game server.
--access to user cash
Select @intCashAmount1 =[amount] FROM [dbo]. [Money] WHERE [userid]= @intUserID1
Select @intCashAmount2 =[amount] FROM [dbo]. [Money] WHERE [userid]= @intUserID2
Select @intCashAmount3 =[amount] FROM [dbo]. [Money] WHERE [userid]= @intUserID3
Select @intCashAmount4 =[amount] FROM [dbo]. [Money] WHERE [userid]= @intUserID4
Create Table #Temp1 (ttemp float)
If @intCashAmount1 + @intWantedAmount1 <0
Begin
Set @FTemp =-@intCashAmount1/@intWantedAmount1
INSERT into #temp1 values (@FTemp)
End
If @intCashAmount2 + @intWantedAmount2 <0
Begin
Set @FTemp =-@intCashAmount2/@intWantedAmount2
INSERT into #temp1 values (@FTemp)
End
If @intCashAmount3 + @intWantedAmount3 <0
Begin
Set @FTemp =-@intCashAmount3/@intWantedAmount3
INSERT into #temp1 values (@FTemp)
End
If @intCashAmount4 + @intWantedAmount4 <0
Begin
Set @FTemp =-@intCashAmount4/@intWantedAmount4
INSERT into #temp1 values (@FTemp)
End
Set @FTemp = (select min (@FTemp) from #temp)
drop table #temp1
If @FTemp < @FRate
Begin
Set @FRate = @FTemp
Set @BNeedReCalc =1
End
If @BNeedReCalc =1
Begin
Set @intWantedAmount1 = @intWantedAmount1 * @FRate
Set @intWantedAmount2 = @intWantedAmount2 * @FRate
Set @intWantedAmount3 = @intWantedAmount3 * @FRate
Set @intWantedAmount4 = @intWantedAmount4 * @FRate
End
Begin TRAN
Exec [Prmoney_updatecash]
@chvModeName, --by what means, such as ' WEB ', ' gameserver ', etc.
@chvSourceName, -the source of the way, such as ' Gold Mahjong server ', ' virtual stock ' and other
@chvRemark, -Other information notes.
@intUserID1, --User ID
0, associated user ID
@intWantedAmount1, -- Number of updates (>0, <0 deduction)
0, -Taxes (tax >0, to be deducted in cash, game server can be set to 0)
@chvIPAddress1 , --IP address
0,--machine code
1 --whether to do log, if >0, it means do log, otherwise do not do log
exec [Prmoney_updatecash]
@chvModeName,--by what means, such as ' WEB ', ' gameserver ', etc.
@chvSourceName, the source of the way, such as ' Gold Mahjong server ', ' virtual stock ' etc.
@chvRemark,--Other informational notes.
@intUserID2,--User ID
0,--related user ID
@intWantedAmount2,--the number of >0 to be updated (plus gold, <0 deduction)
0,--tax (tax >0, to be deducted in cash, game server can be set to 0)
@chvIPAddress2,--IP address
0,--machine code
1-whether log, if >0, it means do log, otherwise do not log
exec [Prmoney_updatecash]
@chvModeName,--by what means, such as ' WEB ', ' gameserver ', etc.
@chvSourceName, the source of the way, such as ' Gold Mahjong server ', ' virtual stock ' etc.
@chvRemark,--Other informational notes.
@intUserID3,--User ID
0,--related user ID
@intWantedAmount3,--the number of >0 to be updated (plus gold, <0 deduction)
0,--tax (tax >0, to be deducted in cash, game server can be set to 0)
@chvIPAddress3,--IP address
0,--machine code
1-whether log, if >0, it means do log, otherwise do not log
exec [Prmoney_updatecash]
@chvModeName,--by what means, such as ' WEB ', ' gameserver ', etc.
@chvSourceName, the source of the way, such as ' Gold Mahjong server ', ' virtual stock ' etc.
@chvRemark,--Other informational notes.
@intUserID4,--User ID
0,--related user ID
@intWantedAmount4,--the number of >0 to be updated (plus gold, <0 deduction)
0,--tax (tax >0, to be deducted in cash, game server can be set to 0)
@chvIPAddress4,--IP address
0,--machine code
1-whether log, if >0, it means do log, otherwise do not log
Commit Tran
Return 1
Go
SET QUOTED_IDENTIFIER OFF
Go
SET an