不实用,之所以写,一为领导的要求,另外也熟悉下写代码,代码多写点也没什么坏处,并且写了之后发现临时表还挺容易用的,数据量小的时候,并显不出临时表速度不行的问题.
代码如下:
SET QUOTED_IDENTIFIER ON GOSET ANSI_NULLS ON GO/*Name:游戏中四人数据同时更新Designed By :whboDesigned At :2005-10-12Modified By :Modified At :Memo:*/
ALTERPROC [PrMoney_UpdateCash2]@chvModeName varchar(16),@chvSourceName varchar(64),@chvRemark varchar(128),@intUserID1 int,@intUserID2 int,@intUserID3 int,@intUserID4 int,@intWantedAmount1 int,@intWantedAmount2 int,@intWantedAmount3 int,@intWantedAmount4 int,@chvIPAddress1 varchar(15),@chvIPAddress2 varchar(15),@chvIPAddress3 varchar(15),@chvIPAddress4 varchar(15),@inyLog tinyintasset nocount on set xact_abort onDeclare @intCashAmount1 int,@intCashAmount2 int,@intCashAmount3 int,@intCashAmount4 intDeclare @FRate float,@FTemp floatDeclare @bNeedReCalc bit; --0:不用重算 ;1:需要重算set @FRate=1.0set @FTemp=1.0set @bNeedReCalc=0Declare @FTemp1 float,@FTemp2 float,@FTemp3 float,@FTemp4 float
--这里要注意,更新用户现金取数据库中的数据,跟游戏服务器能否保持一致--取得用户现金select @intCashAmount1=[Amount] from [dbo].[Money] where [UserID]=@intUserID1select @intCashAmount2=[Amount] from [dbo].[Money] where [UserID]=@intUserID2select @intCashAmount3=[Amount] from [dbo].[Money] where [UserID]=@intUserID3select @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<0begin set @FTemp=-@intCashAmount2/@intWantedAmount2 insert into #temp1 values(@FTemp)end
if @intCashAmount3+@intWantedAmount3<0begin set @FTemp=-@intCashAmount3/@intWantedAmount3 insert into #temp1 values(@FTemp)end
if @intCashAmount4+@intWantedAmount4<0begin set @FTemp=-@intCashAmount4/@intWantedAmount4 insert into #temp1 values(@FTemp)end
set @FTemp=(select min(@FTemp) from #temp)drop table #temp1
if @FTemp<@FRatebeginset @FRate=@FTempset @BNeedReCalc=1end
if @BNeedReCalc=1 beginset @intWantedAmount1=@intWantedAmount1*@FRateset @intWantedAmount2=@intWantedAmount2*@FRateset @intWantedAmount3=@intWantedAmount3*@FRateset @intWantedAmount4=@intWantedAmount4*@FRateend
begin tranexec [prMoney_UpdateCash]@chvModeName,-- 通过什么方式,如'WEB'、'GameServer'等@chvSourceName,; -- 方式的源,如'金币麻将服务器'、'虚拟股市'等@chvRemark,; -- 其它信息 注释.@intUserID1,;-- 用户ID0, -- 相关的用户ID@intWantedAmount1,-- 希望更新的数量(>0 加金, <0 扣金)0,;-- 税金(税金>0,要在现金中扣除,游戏服务器可以置为0)@chvIPAddress1,; -- IP地址0, -- 机器码1;-- 是否做Log,如果>0,则表示做Log,否则不做Log
exec [prMoney_UpdateCash]@chvModeName,-- 通过什么方式,如'WEB'、'GameServer'等@chvSourceName,; -- 方式的源,如'金币麻将服务器'、'虚拟股市'等@chvRemark,; -- 其它信息 注释.@intUserID2,;-- 用户ID0, -- 相关的用户ID@intWantedAmount2,-- 希望更新的数量(>0 加金, <0 扣金)0,;-- 税金(税金>0,要在现金中扣除,游戏服务器可以置为0)@chvIPAddress2,; -- IP地址0, -- 机器码1;-- 是否做Log,如果>0,则表示做Log,否则不做Log
exec [prMoney_UpdateCash]@chvModeName,-- 通过什么方式,如'WEB'、'GameServer'等@chvSourceName,; -- 方式的源,如'金币麻将服务器'、'虚拟股市'等@chvRemark,; -- 其它信息 注释.@intUserID3,;-- 用户ID0, -- 相关的用户ID@intWantedAmount3,-- 希望更新的数量(>0 加金, <0 扣金)0,;-- 税金(税金>0,要在现金中扣除,游戏服务器可以置为0)@chvIPAddress3,; -- IP地址0, -- 机器码1;-- 是否做Log,如果>0,则表示做Log,否则不做Logexec [prMoney_UpdateCash]@chvModeName,-- 通过什么方式,如'WEB'、'GameServer'等@chvSourceName,; -- 方式的源,如'金币麻将服务器'、'虚拟股市'等@chvRemark,; -- 其它信息 注释.@intUserID4,;-- 用户ID0, -- 相关的用户ID@intWantedAmount4,-- 希望更新的数量(>0 加金, <0 扣金)0,;-- 税金(税金>0,要在现金中扣除,游戏服务器可以置为0)@chvIPAddress4,; -- IP地址0, -- 机器码1;-- 是否做Log,如果>0,则表示做Log,否则不做Logcommit tranreturn 1
GOSET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GO