0
をWHILEループ方式を変更すると、農産物を実行する際に通過したパラメータに基づいて、フィクスチャテーブルを決定する:私はそれ以下のストアドプロシージャを持っている設定に基づくするロジック
「LL」は、最後の16チーム
「QFを意味しますSF 『という意味の最後の4つのチーム
『'最後の8つのチーム
は意味』FF』を意味し、事実上のチームを失う最後の2つのチーム
は、各ステージの下にチームを短縮するためにノックアウトされています。以下の手順は機能しますが、事実上、3つの回転ループをより基本的なものに置き換えて、誰かがこれを含むようにコードを操作する方法を知っているかどうかを見たいと思っていますか?以下は
は手順です:
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[InsertFixture_EUCompetition]
-- Add the parameters for the stored procedure here
-- exec InsertFixture_EUCompetition 1
@SeasonID INT,
@MatchType CHAR(2)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @WeekNumber INT
DECLARE @FixtureDate DATE
DECLARE @HomeTeamID INT
DECLARE @AwayTeamID INT
DECLARE @LeagueID INT
-- Insert statements for procedure here
SELECT * INTO #TempCompetition FROM [dbo].[EUCompetition] where SeasonID = @SeasonID
-- SELECT * FROM [dbo].[EUCompetition] where SeasonID = 1
set @WeekNumber = 1
set @FixtureDate = GETDATE()
WHILE((SELECT COUNT(1) FROM #TempCompetition) > 0)
BEGIN
SELECT @LeagueID = MAX(LeagueID) from #TempCompetition
IF @MatchType = 'LL'
BEGIN
INSERT EUFixture (MatchType, WeekNumber, FixtureDate, HomeTeamID, HomeScore, AwayTeamID, AwayScore, HomeTeamResult, AwayTeamResult, LeagueID, CurrentSeason)
VALUES (@MatchType, @WeekNumber , @FixtureDate,
(Select TeamId from #TempCompetition where Position = 1 and LeagueID = @LeagueID) , null,
(Select TeamId from #TempCompetition where Position = 4 and LeagueID = @LeagueID) , null,
null, null, @LeagueID , @SeasonID)
INSERT EUFixture (MatchType, WeekNumber, FixtureDate, HomeTeamID, HomeScore, AwayTeamID, AwayScore, HomeTeamResult, AwayTeamResult, LeagueID, CurrentSeason)
VALUES ( @MatchType, @WeekNumber , @FixtureDate,
(Select TeamId from #TempCompetition where Position = 2 and LeagueID = @LeagueID) , null,
(Select TeamId from #TempCompetition where Position = 3 and LeagueID = @LeagueID) , null,
null, null, @LeagueID , @SeasonID)
RETURN
END
DELETE #TempCompetition WHERE LeagueID = @LeagueID
set @WeekNumber = @WeekNumber + 1
set @FixtureDate = DATEADD(day,1,@FixtureDate)
END
DROP TABLE #TempCompetition
DECLARE @I INT
IF @MatchType = 'QF'
SET @I = 1
WHILE(@I < 5)
BEGIN
set @WeekNumber = @WeekNumber + 1
set @FixtureDate = DATEADD(day,1,@FixtureDate)
INSERT EUFixture (MatchType, WeekNumber, FixtureDate, HomeTeamID, HomeScore, AwayTeamID, AwayScore, HomeTeamResult, AwayTeamResult, LeagueID, CurrentSeason)
VALUES ( 'QF' , @WeekNumber, @FixtureDate , NULL, NULL,NULL,NULL,NULL,NULL,NULL,@SeasonID)
SET @I = @I +1
END
IF @MatchType = 'SF'
SET @I = 1
WHILE(@I < 3)
BEGIN
set @WeekNumber = @WeekNumber + 1
set @FixtureDate = DATEADD(day,1,@FixtureDate)
INSERT EUFixture (MatchType, WeekNumber, FixtureDate, HomeTeamID, HomeScore, AwayTeamID, AwayScore, HomeTeamResult, AwayTeamResult, LeagueID, CurrentSeason)
VALUES ( 'SF' , @WeekNumber, @FixtureDate , NULL, NULL,NULL,NULL,NULL,NULL,NULL,@SeasonID)
SET @I = @I +1
END
IF @MatchType = 'FF'
SET @I = 1
WHILE(@I < 2)
BEGIN
set @WeekNumber = @WeekNumber + 1
set @FixtureDate = DATEADD(day,1,@FixtureDate)
INSERT EUFixture (MatchType, WeekNumber, FixtureDate, HomeTeamID, HomeScore, AwayTeamID, AwayScore, HomeTeamResult, AwayTeamResult, LeagueID, CurrentSeason)
VALUES ( 'FF' , @WeekNumber, @FixtureDate , NULL, NULL,NULL,NULL,NULL,NULL,NULL,@SeasonID)
SET @I = @I +1
END
END
はこのような何か試してみてください、あなたに非常に多くの
を、あなたの手順は論理的に正しいですか?たとえば、@HomeTeamIdが使用されていない場合、MAX @ LeagueIDのプロシージャを終了する 'IF @MatchType = 'LL''にRETURNがあり、すべての呼び出しで@WeekNumberが再計算されます(QFとSFが重複する可能性があります)。 –
最後のwhileループは一度しか実行されないので、最後のwhileループを取り除くことができます。 – Anand