下面的脚本一切正常,直到我尝试添加带有 SELECT 子句的 Case 语句 我已经这样做以使用正确的日期自动填充表,可以让我知道我做错了什么吗?
DECLARE @PitchType_Skey INT
DECLARE @Site_Skey INT
DECLARE @Capacity INT
DECLARE @StartDate DATE
DECLARE @EndDate DATE
SET @PitchType_Skey = 1
SET @Site_Skey = 1
SET @Capacity = 0
WHILE (@Site_Skey < 127)
BEGIN
IF @PitchType_Skey = 8
BEGIN
SET @PitchType_Skey = 1
SET @Site_Skey = @Site_Skey + 1
END
IF (@Site_Skey < 127)
BEGIN
Set @Capacity = (SELECT SiteWeighting From Site Where Site_Skey = @Site_Skey)
Set @Capacity = @Capacity * (SELECT PitchTypeWeighting From PitchType Where PitchType_Skey = @PitchType_Skey)
Set @Capacity = @Capacity * ((10*(100+((RAND()*40)-20)))*0.01)
INSERT INTO Capacity
SELECT
CASE @StartDate
WHEN (SELECT SiteWeighting FROM Site WHERE SiteWeighting = 1 THEN 01/05/2010) ELSE,
WHEN (SELECT SiteWeighting FROM Site WHERE SiteWeighting = 2 THEN 01/04/2010) ELSE,
WHEN (SELECT SiteWeighting FROM Site WHERE SiteWeighting = 3 THEN 01/04/2010) ELSE,
WHEN (SELECT SiteWeighting FROM Site WHERE SiteWeighting = 4 THEN 01/01/2010) ELSE,
CASE @EndDate
WHEN (SELECT SiteWeighting FROM Site WHERE SiteWeighting = 1 THEN 30/09/2010) ELSE,
WHEN (SELECT SiteWeighting FROM Site WHERE SiteWeighting = 2 THEN 01/11/2010) ELSE,
WHEN (SELECT SiteWeighting FROM Site WHERE SiteWeighting = 3 THEN 01/11/2010) ELSE,
WHEN (SELECT SiteWeighting FROM Site WHERE SiteWeighting = 4 THEN 01/12/2010) ELSE,
round(@Capacity,0) as Capacity,
@PitchType_Skey, @Site_Skey
END
SET @PitchType_Skey = @PitchType_Skey + 1
END