日期:2014-05-16 浏览次数:20609 次
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[c_DueConscriptionQueue]
@ID INT
AS
IF NOT EXISTS ( SELECT [ID]
FROM [Conscription_Queue]
WHERE [ID] = @ID
AND [Completed] = 0 )
BEGIN
RETURN 0
END
DECLARE @TroopID INT
DECLARE @VillageID INT
DECLARE @UnitTraining INT
DECLARE @NextUnit DATETIME
DECLARE @Total INT
DECLARE @Count INT
SELECT @VillageID = [VillageID], @TroopID = [TroopID], @NextUnit = [NextUnit], @UnitTraining = [UnitTraining], @Total = [Total]
FROM [Conscription_Queue]
WHERE [ID] = @ID
IF ( @UnitTraining <> 0 )
BEGIN
SET @Count = DATEDIFF(s, @NextUnit, GETDATE()) / @UnitTraining + 1
END
ELSE
BEGIN
RETURN 0
END
--检查是否已存在兵种,不存在新增,存在 增加数量
IF NOT EXISTS ( SELECT *
FROM [Village_Troops]
WHERE [VillageID] = @VillageID
AND [InVillageID] = @VillageID
AND [TroopID] = @TroopID
AND [GarrisonType] = 1 )
BEGIN
IF ( @Count > @Total )
BEGIN
SET @Count = @Total
END
INSERT INTO [Village_Troops] ( [TroopID], [quantity], [VillageID], [InVillageID], [GarrisonType] )
VALUES ( @TroopID, @Count, @VillageID, @VillageID, 1 )
END
ELSE
BEGIN
IF ( @Count&n