不實用,之所以寫,一為領導的要求,另外也熟悉下寫代碼,代碼多寫點也沒什么壞處,并且寫了之后發現臨時表還挺容易用的,數據量小的時候,并顯不出臨時表速度不行的問題.
代碼如下:
set quoted_identifier on
go
set ansi_nulls on
go
/*
name:游戲中四人數據同時更新
designed by :whbo
designed at :2005-10-12
modified by :
modified at :
memo:
*/
alter proc [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 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:不用重算 ;1:需要重算
set @frate=1.0
set @ftemp=1.0
set @bneedrecalc=0
declare @ftemp1 float,@ftemp2 float,@ftemp3 float,@ftemp4 float
--這里要注意,更新用戶現金取數據庫中的數據,跟游戲服務器能否保持一致
--取得用戶現金
select @intcashamount1=[amount] from [dbo].[money] where [userid][email protected]
select @intcashamount2=[amount] from [dbo].[money] where [userid][email protected]
select @intcashamount3=[amount] from [dbo].[money] where [userid][email protected]
select @intcashamount4=[amount] from [dbo].[money] where [userid][email protected]
create table #temp1(ttemp float)
if @[email protected]<0
begin
set @[email protected]/@intwantedamount1
insert into #temp1 values(@ftemp)
end
if @[email protected]<0
begin
set @[email protected]/@intwantedamount2
insert into #temp1 values(@ftemp)
end
if @[email protected]<0
begin
set @[email protected]/@intwantedamount3
insert into #temp1 values(@ftemp)
end
if @[email protected]<0
begin
set @[email protected]/@intwantedamount4
insert into #temp1 values(@ftemp)
end
set @ftemp=(select min(@ftemp) from #temp)
drop table #temp1
if @ftemp<@frate
begin
set @[email protected]
set @bneedrecalc=1
end
if @bneedrecalc=1
begin
set @[email protected]*@frate
set @[email protected]*@frate
set @[email protected]*@frate
set @[email protected]*@frate
end
begin tran
exec [prmoney_updatecash]
@chvmodename, -- 通過什么方式,如'web'、'gameserver'等
@chvsourcename, -- 方式的源,如'金幣麻將服務器'、'虛擬股市'等
@chvremark, -- 其它信息 注釋.
@intuserid1, -- 用戶id
0, -- 相關的用戶id
@intwantedamount1, -- 希望更新的數量(>0 加金, <0 扣金)
0, -- 稅金(稅金>0,要在現金中扣除,游戲服務器可以置為0)
@chvipaddress1, -- ip地址
0, -- 機器碼
1 -- 是否做log,如果>0,則表示做log,否則不做log
exec [prmoney_updatecash]
@chvmodename, -- 通過什么方式,如'web'、'gameserver'等
@chvsourcename, -- 方式的源,如'金幣麻將服務器'、'虛擬股市'等
@chvremark, -- 其它信息 注釋.
@intuserid2, -- 用戶id
0, -- 相關的用戶id
@intwantedamount2, -- 希望更新的數量(>0 加金, <0 扣金)
0, -- 稅金(稅金>0,要在現金中扣除,游戲服務器可以置為0)
@chvipaddress2, -- ip地址
0, -- 機器碼
1 -- 是否做log,如果>0,則表示做log,否則不做log
exec [prmoney_updatecash]
@chvmodename, -- 通過什么方式,如'web'、'gameserver'等
@chvsourcename, -- 方式的源,如'金幣麻將服務器'、'虛擬股市'等
@chvremark, -- 其它信息 注釋.
@intuserid3, -- 用戶id
0, -- 相關的用戶id
@intwantedamount3, -- 希望更新的數量(>0 加金, <0 扣金)
0, -- 稅金(稅金>0,要在現金中扣除,游戲服務器可以置為0)
@chvipaddress3, -- ip地址
0, -- 機器碼
1 -- 是否做log,如果>0,則表示做log,否則不做log
exec [prmoney_updatecash]
@chvmodename, -- 通過什么方式,如'web'、'gameserver'等
@chvsourcename, -- 方式的源,如'金幣麻將服務器'、'虛擬股市'等
@chvremark, -- 其它信息 注釋.
@intuserid4, -- 用戶id
0, -- 相關的用戶id
@intwantedamount4, -- 希望更新的數量(>0 加金, <0 扣金)
0, -- 稅金(稅金>0,要在現金中扣除,游戲服務器可以置為0)
@chvipaddress4, -- ip地址
0, -- 機器碼
1 -- 是否做log,如果>0,則表示做log,否則不做log
commit tran
return 1
go
set quoted_identifier off
go
set an
新聞熱點
疑難解答