日期:2014-05-17 浏览次数:20423 次
USE [db]
GO
/****** Object: StoredProcedure [dbo].[XMUserAllot] Script Date: 2013/8/29 23:29:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[XMUserAllot]
@UserName varchar(25)
AS
begin
SET NOCOUNT ON;
declare @UserId int,
@ThisUser varchar(25),
@AllotCount smallint,
@RightCount smallint,
@LeftCount smallint
if(@UserName is null)
declare XM_Cursor cursor forward_only static for select [username],[defaultshouquan] from ShouQuanUsers where defaultshouquan>0
else
declare XM_Cursor cursor forward_only static for select [username],[defaultshouquan] from ShouQuanUsers where defaultshouquan>0 and [username]=@UserName
open XM_Cursor
fetch next from XM_Cursor into @ThisUser,@AllotCount
while(@@FETCH_STATUS=0)
begin
select @UserId=[Id] from [User] where UserName=@ThisUser
if(@UserId is not null)
begin
select @RightCount=count(*) from XMUsers where userid=@UserId
set @LeftCount= @AllotCount-@RightCount
if(@LeftCount>0)
update top(@LeftCount) XMUsers set userid=@UserId where userid is null
end
fetch next from XM_Cursor into @ThisUser,@AllotCount
set @UserId=null
end
close XM_Cursor
deallocate XM_Cursor
end
CREATE PROCEDURE [dbo].[XMUserAllot] @UserName VARCHAR(25)