· 5 years ago · May 05, 2020, 11:36 PM
1USE [FootballDataWarehouse]
2GO
3
4DROP TABLE IF EXISTS dbo.TeamStatisticTempTable
5CREATE TABLE TeamStatisticTempTable(
6 TeamName nvarchar(100) NOT NULL,
7 MatchesPlayed int NOT NULL,
8 Wins int NOT NULL,
9 Loses int NOT NULL,
10 Draws int NOT NULL,
11 GoalsScored int NOT NULL,
12 GoalsConceded int NOT NULL,
13 GoalDifference int NOT NULL,
14 AVG float NOT NULL,
15 PTS int not null,
16 Month nvarchar(30) not null
17);
18
19GO
20DECLARE @TotalSeasons INT
21DECLARE @Year INT
22DECLARE @SeasonID INT
23SET @TotalSeasons = (SELECT MAX(s.ID) FROM Seasons s)
24SET @SeasonID = (SELECT MIN(ID) FROM Seasons)
25
26WHILE (@SeasonID <= @TotalSeasons)
27BEGIN
28 SET @Year = (SELECT SUBSTRING(Season, 1, 4) FROM Seasons WHERE ID = @SeasonID)
29 EXEC iyx_2 @ssId = @SeasonID, @yr = @Year
30 SET @SeasonID = @SeasonID + 1
31END
32
33SELECT * FROM dbo.TeamStatisticTempTable
34ORDER BY TeamName
35DROP TABLE dbo.TeamStatisticTempTable
36GO