错误“'GO'附近的语法不正确。期待对话。”在最后一个代码行和前一行包含“结束”。
包括整个函数,因为语法中有许多匹配的END。
CREATE PROCEDURE UpdateMatrices
-- Add the parameters for the stored procedure here
@InstitutionId uniqueidentifier,
@PopulationName int = -1,
@BBB1AAA1 int, @BBB2AAA1 int, @BBB3AAA1 int, @BBB4AAA1 int, @BBB5AAA1 int, @BBB6AAA1 int, @BBB7AAA1 int, @BBB8AAA1 int, @BBB9AAA1 int, @BBB10AAA1 int,
@BBB1AAA2 int, @BBB2AAA2 int, @BBB3AAA2 int, @BBB4AAA2 int, @BBB5AAA2 int, @BBB6AAA2 int, @BBB7AAA2 int, @BBB8AAA2 int, @BBB9AAA2 int, @BBB10AAA2 int,
@BBB1AAA3 int, @BBB2AAA3 int, @BBB3AAA3 int, @BBB4AAA3 int, @BBB5AAA3 int, @BBB6AAA3 int, @BBB7AAA3 int, @BBB8AAA3 int, @BBB9AAA3 int, @BBB10AAA3 int,
@BBB1AAA4 int, @BBB2AAA4 int, @BBB3AAA4 int, @BBB4AAA4 int, @BBB5AAA4 int, @BBB6AAA4 int, @BBB7AAA4 int, @BBB8AAA4 int, @BBB9AAA4 int, @BBB10AAA4 int,
@BBB1AAA5 int, @BBB2AAA5 int, @BBB3AAA5 int, @BBB4AAA5 int, @BBB5AAA5 int, @BBB6AAA5 int, @BBB7AAA5 int, @BBB8AAA5 int, @BBB9AAA5 int, @BBB10AAA5 int,
@BBB1AAA6 int, @BBB2AAA6 int, @BBB3AAA6 int, @BBB4AAA6 int, @BBB5AAA6 int, @BBB6AAA6 int, @BBB7AAA6 int, @BBB8AAA6 int, @BBB9AAA6 int, @BBB10AAA6 int,
@BBB1AAA7 int, @BBB2AAA7 int, @BBB3AAA7 int, @BBB4AAA7 int, @BBB5AAA7 int, @BBB6AAA7 int, @BBB7AAA7 int, @BBB8AAA7 int, @BBB9AAA7 int, @BBB10AAA7 int,
@BBB1AAA8 int, @BBB2AAA8 int, @BBB3AAA8 int, @BBB4AAA8 int, @BBB5AAA8 int, @BBB6AAA8 int, @BBB7AAA8 int, @BBB8AAA8 int, @BBB9AAA8 int, @BBB10AAA8 int,
@BBB1AAA9 int, @BBB2AAA9 int, @BBB3AAA9 int, @BBB4AAA9 int, @BBB5AAA9 int, @BBB6AAA9 int, @BBB7AAA9 int, @BBB8AAA9 int, @BBB9AAA9 int, @BBB10AAA9 int,
@BBB1AAA10 int, @BBB2AAA10 int, @BBB3AAA10 int, @BBB4AAA10 int, @BBB5AAA10 int, @BBB6AAA10 int, @BBB7AAA10 int, @BBB8AAA10 int, @BBB9AAA10 int, @BBB10AAA10 int
AS
--DECLARE @BUCKETVALUEDYNAMIC int
BEGIN
DECLARE @AAAI int, @BBBI int
SET @AAAI =1
SET @BBBI = 1
WHILE @AAAI < 10
WHILE @BBBI < 10
update [npc2].[t_MERIT_grantBucket]
SET [grantBucketValue] =
CASE @AAAI WHEN 1 THEN CASE @BBBI WHEN 1 THEN @BBB1AAA1
WHEN 2 THEN @BBB2AAA1
WHEN 3 THEN @BBB3AAA1
WHEN 4 THEN @BBB4AAA1
WHEN 5 THEN @BBB5AAA1
WHEN 6 THEN @BBB6AAA1
WHEN 7 THEN @BBB7AAA1
WHEN 8 THEN @BBB8AAA1
WHEN 9 THEN @BBB9AAA1
WHEN 10 THEN @BBB10AAA1 END
WHEN 2 THEN CASE @BBBI WHEN 1 THEN @BBB1AAA2
WHEN 2 THEN @BBB2AAA2
WHEN 3 THEN @BBB3AAA2
WHEN 4 THEN @BBB4AAA2
WHEN 5 THEN @BBB5AAA2
WHEN 6 THEN @BBB6AAA2
WHEN 7 THEN @BBB7AAA2
WHEN 8 THEN @BBB8AAA2
WHEN 9 THEN @BBB9AAA2
WHEN 10 THEN @BBB10AAA2 END
WHEN 3 THEN CASE @BBBI WHEN 1 THEN @BBB1AAA3
WHEN 2 THEN @BBB2AAA3
WHEN 3 THEN @BBB3AAA3
WHEN 4 THEN @BBB4AAA3
WHEN 5 THEN @BBB5AAA3
WHEN 6 THEN @BBB6AAA3
WHEN 7 THEN @BBB7AAA3
WHEN 8 THEN @BBB8AAA3
WHEN 9 THEN @BBB9AAA3
WHEN 10 THEN @BBB10AAA3 END
WHEN 4 THEN CASE @BBBI WHEN 1 THEN @BBB1AAA4
WHEN 2 THEN @BBB2AAA4
WHEN 3 THEN @BBB3AAA4
WHEN 4 THEN @BBB4AAA4
WHEN 5 THEN @BBB5AAA4
WHEN 6 THEN @BBB6AAA4
WHEN 7 THEN @BBB7AAA4
WHEN 8 THEN @BBB8AAA4
WHEN 9 THEN @BBB9AAA4
WHEN 10 THEN @BBB10AAA4 END
WHEN 5 THEN CASE @BBBI WHEN 1 THEN @BBB1AAA5
WHEN 2 THEN @BBB2AAA5
WHEN 3 THEN @BBB3AAA5
WHEN 4 THEN @BBB4AAA5
WHEN 5 THEN @BBB5AAA5
WHEN 6 THEN @BBB6AAA5
WHEN 7 THEN @BBB7AAA5
WHEN 8 THEN @BBB8AAA5
WHEN 9 THEN @BBB9AAA5
WHEN 10 THEN @BBB10AAA5 END
WHEN 6 THEN CASE @BBBI WHEN 1 THEN @BBB1AAA6
WHEN 2 THEN @BBB2AAA6
WHEN 3 THEN @BBB3AAA6
WHEN 4 THEN @BBB4AAA6
WHEN 5 THEN @BBB5AAA6
WHEN 6 THEN @BBB6AAA6
WHEN 7 THEN @BBB7AAA6
WHEN 8 THEN @BBB8AAA6
WHEN 9 THEN @BBB9AAA6
WHEN 10 THEN @BBB10AAA6 END
WHEN 7 THEN CASE @BBBI WHEN 1 THEN @BBB1AAA7
WHEN 2 THEN @BBB2AAA7
WHEN 3 THEN @BBB3AAA7
WHEN 4 THEN @BBB4AAA7
WHEN 5 THEN @BBB5AAA7
WHEN 6 THEN @BBB6AAA7
WHEN 7 THEN @BBB7AAA7
WHEN 8 THEN @BBB8AAA7
WHEN 9 THEN @BBB9AAA7
WHEN 10 THEN @BBB10AAA7 END
WHEN 8 THEN CASE @BBBI WHEN 1 THEN @BBB1AAA8
WHEN 2 THEN @BBB2AAA8
WHEN 3 THEN @BBB3AAA8
WHEN 4 THEN @BBB4AAA8
WHEN 5 THEN @BBB5AAA8
WHEN 6 THEN @BBB6AAA8
WHEN 7 THEN @BBB7AAA8
WHEN 8 THEN @BBB8AAA8
WHEN 9 THEN @BBB9AAA8
WHEN 10 THEN @BBB10AAA8 END
WHEN 9 THEN CASE @BBBI WHEN 1 THEN @BBB1AAA9
WHEN 2 THEN @BBB2AAA9
WHEN 3 THEN @BBB3AAA9
WHEN 4 THEN @BBB4AAA9
WHEN 5 THEN @BBB5AAA9
WHEN 6 THEN @BBB6AAA9
WHEN 7 THEN @BBB7AAA9
WHEN 8 THEN @BBB8AAA9
WHEN 9 THEN @BBB9AAA9
WHEN 10 THEN @BBB10AAA9 END
WHEN 10 THEN CASE @BBBI WHEN 1 THEN @BBB1AAA10
WHEN 2 THEN @BBB2AAA10
WHEN 3 THEN @BBB3AAA10
WHEN 4 THEN @BBB4AAA10
WHEN 5 THEN @BBB5AAA10
WHEN 6 THEN @BBB6AAA10
WHEN 7 THEN @BBB7AAA10
WHEN 8 THEN @BBB8AAA10
WHEN 9 THEN @BBB9AAA10
WHEN 10 THEN @BBB10AAA10 END
END
WHERE institutionID LIKE @InstitutionId AND PopulationName = @PopulationName AND BBB = @BBBI AND AAA = @AAAI
SET @BBBI = @BBBI + 1
END --BBBLoop
SET @AAAI = @AAAI + 1
END --AAA
END
GO
为什么?
答案 0 :(得分:0)
这不是您问题的实际答案(您已经在评论中得到了答案)。这就是你可以用更好的结果和可读性编写查询的方法。
您的逻辑当前是错误的,并且没有更新您期望的行。 以下脚本仅执行1次更新,因此您可以获得更好的性能并且不会有死锁的风险。放弃循环并尝试这样做:
CREATE PROCEDURE UpdateMatrices
-- Add the parameters for the stored procedure here
@InstitutionId uniqueidentifier,
@PopulationName int = -1,
@BBB1AAA1 int, @BBB2AAA1 int, @BBB3AAA1 int, @BBB4AAA1 int, @BBB5AAA1 int, @BBB6AAA1 int, @BBB7AAA1 int, @BBB8AAA1 int, @BBB9AAA1 int, @BBB10AAA1 int,
@BBB1AAA2 int, @BBB2AAA2 int, @BBB3AAA2 int, @BBB4AAA2 int, @BBB5AAA2 int, @BBB6AAA2 int, @BBB7AAA2 int, @BBB8AAA2 int, @BBB9AAA2 int, @BBB10AAA2 int,
@BBB1AAA3 int, @BBB2AAA3 int, @BBB3AAA3 int, @BBB4AAA3 int, @BBB5AAA3 int, @BBB6AAA3 int, @BBB7AAA3 int, @BBB8AAA3 int, @BBB9AAA3 int, @BBB10AAA3 int,
@BBB1AAA4 int, @BBB2AAA4 int, @BBB3AAA4 int, @BBB4AAA4 int, @BBB5AAA4 int, @BBB6AAA4 int, @BBB7AAA4 int, @BBB8AAA4 int, @BBB9AAA4 int, @BBB10AAA4 int,
@BBB1AAA5 int, @BBB2AAA5 int, @BBB3AAA5 int, @BBB4AAA5 int, @BBB5AAA5 int, @BBB6AAA5 int, @BBB7AAA5 int, @BBB8AAA5 int, @BBB9AAA5 int, @BBB10AAA5 int,
@BBB1AAA6 int, @BBB2AAA6 int, @BBB3AAA6 int, @BBB4AAA6 int, @BBB5AAA6 int, @BBB6AAA6 int, @BBB7AAA6 int, @BBB8AAA6 int, @BBB9AAA6 int, @BBB10AAA6 int,
@BBB1AAA7 int, @BBB2AAA7 int, @BBB3AAA7 int, @BBB4AAA7 int, @BBB5AAA7 int, @BBB6AAA7 int, @BBB7AAA7 int, @BBB8AAA7 int, @BBB9AAA7 int, @BBB10AAA7 int,
@BBB1AAA8 int, @BBB2AAA8 int, @BBB3AAA8 int, @BBB4AAA8 int, @BBB5AAA8 int, @BBB6AAA8 int, @BBB7AAA8 int, @BBB8AAA8 int, @BBB9AAA8 int, @BBB10AAA8 int,
@BBB1AAA9 int, @BBB2AAA9 int, @BBB3AAA9 int, @BBB4AAA9 int, @BBB5AAA9 int, @BBB6AAA9 int, @BBB7AAA9 int, @BBB8AAA9 int, @BBB9AAA9 int, @BBB10AAA9 int,
@BBB1AAA10 int, @BBB2AAA10 int, @BBB3AAA10 int, @BBB4AAA10 int, @BBB5AAA10 int, @BBB6AAA10 int, @BBB7AAA10 int, @BBB8AAA10 int, @BBB9AAA10 int, @BBB10AAA10 int
AS
BEGIN
update [npc2].[t_MERIT_grantBucket]
SET [grantBucketValue] =
CASE AAA WHEN 1 THEN CASE BBB WHEN 1 THEN @BBB1AAA1
WHEN 2 THEN @BBB2AAA1
WHEN 3 THEN @BBB3AAA1
WHEN 4 THEN @BBB4AAA1
WHEN 5 THEN @BBB5AAA1
WHEN 6 THEN @BBB6AAA1
WHEN 7 THEN @BBB7AAA1
WHEN 8 THEN @BBB8AAA1
WHEN 9 THEN @BBB9AAA1
WHEN 10 THEN @BBB10AAA1 END
WHEN 2 THEN CASE BBB WHEN 1 THEN @BBB1AAA2
WHEN 2 THEN @BBB2AAA2
WHEN 3 THEN @BBB3AAA2
WHEN 4 THEN @BBB4AAA2
WHEN 5 THEN @BBB5AAA2
WHEN 6 THEN @BBB6AAA2
WHEN 7 THEN @BBB7AAA2
WHEN 8 THEN @BBB8AAA2
WHEN 9 THEN @BBB9AAA2
WHEN 10 THEN @BBB10AAA2 END
WHEN 3 THEN CASE BBB WHEN 1 THEN @BBB1AAA3
WHEN 2 THEN @BBB2AAA3
WHEN 3 THEN @BBB3AAA3
WHEN 4 THEN @BBB4AAA3
WHEN 5 THEN @BBB5AAA3
WHEN 6 THEN @BBB6AAA3
WHEN 7 THEN @BBB7AAA3
WHEN 8 THEN @BBB8AAA3
WHEN 9 THEN @BBB9AAA3
WHEN 10 THEN @BBB10AAA3 END
WHEN 4 THEN CASE BBB WHEN 1 THEN @BBB1AAA4
WHEN 2 THEN @BBB2AAA4
WHEN 3 THEN @BBB3AAA4
WHEN 4 THEN @BBB4AAA4
WHEN 5 THEN @BBB5AAA4
WHEN 6 THEN @BBB6AAA4
WHEN 7 THEN @BBB7AAA4
WHEN 8 THEN @BBB8AAA4
WHEN 9 THEN @BBB9AAA4
WHEN 10 THEN @BBB10AAA4 END
WHEN 5 THEN CASE BBB WHEN 1 THEN @BBB1AAA5
WHEN 2 THEN @BBB2AAA5
WHEN 3 THEN @BBB3AAA5
WHEN 4 THEN @BBB4AAA5
WHEN 5 THEN @BBB5AAA5
WHEN 6 THEN @BBB6AAA5
WHEN 7 THEN @BBB7AAA5
WHEN 8 THEN @BBB8AAA5
WHEN 9 THEN @BBB9AAA5
WHEN 10 THEN @BBB10AAA5 END
WHEN 6 THEN CASE BBB WHEN 1 THEN @BBB1AAA6
WHEN 2 THEN @BBB2AAA6
WHEN 3 THEN @BBB3AAA6
WHEN 4 THEN @BBB4AAA6
WHEN 5 THEN @BBB5AAA6
WHEN 6 THEN @BBB6AAA6
WHEN 7 THEN @BBB7AAA6
WHEN 8 THEN @BBB8AAA6
WHEN 9 THEN @BBB9AAA6
WHEN 10 THEN @BBB10AAA6 END
WHEN 7 THEN CASE BBB WHEN 1 THEN @BBB1AAA7
WHEN 2 THEN @BBB2AAA7
WHEN 3 THEN @BBB3AAA7
WHEN 4 THEN @BBB4AAA7
WHEN 5 THEN @BBB5AAA7
WHEN 6 THEN @BBB6AAA7
WHEN 7 THEN @BBB7AAA7
WHEN 8 THEN @BBB8AAA7
WHEN 9 THEN @BBB9AAA7
WHEN 10 THEN @BBB10AAA7 END
WHEN 8 THEN CASE BBB WHEN 1 THEN @BBB1AAA8
WHEN 2 THEN @BBB2AAA8
WHEN 3 THEN @BBB3AAA8
WHEN 4 THEN @BBB4AAA8
WHEN 5 THEN @BBB5AAA8
WHEN 6 THEN @BBB6AAA8
WHEN 7 THEN @BBB7AAA8
WHEN 8 THEN @BBB8AAA8
WHEN 9 THEN @BBB9AAA8
WHEN 10 THEN @BBB10AAA8 END
WHEN 9 THEN CASE BBB WHEN 1 THEN @BBB1AAA9
WHEN 2 THEN @BBB2AAA9
WHEN 3 THEN @BBB3AAA9
WHEN 4 THEN @BBB4AAA9
WHEN 5 THEN @BBB5AAA9
WHEN 6 THEN @BBB6AAA9
WHEN 7 THEN @BBB7AAA9
WHEN 8 THEN @BBB8AAA9
WHEN 9 THEN @BBB9AAA9
WHEN 10 THEN @BBB10AAA9 END
WHEN 10 THEN CASE BBB WHEN 1 THEN @BBB1AAA10
WHEN 2 THEN @BBB2AAA10
WHEN 3 THEN @BBB3AAA10
WHEN 4 THEN @BBB4AAA10
WHEN 5 THEN @BBB5AAA10
WHEN 6 THEN @BBB6AAA10
WHEN 7 THEN @BBB7AAA10
WHEN 8 THEN @BBB8AAA10
WHEN 9 THEN @BBB9AAA10
WHEN 10 THEN @BBB10AAA10 END
END
WHERE institutionID LIKE @InstitutionId AND PopulationName = @PopulationName AND
BBB between 1 and 10 and AAA between 1 and 10
END
答案 1 :(得分:-3)
我犯的错误在下面纠正。 @ChrisGheen注意到了愚蠢的错误。
BEGIN
DECLARE @ACRKI int, @NDRKI int
SET @ACRKI =1
SET @NDRKI = 1
BEGIN --HERE
BEGIN -- AND HERE
WHILE @ACRKI < 10
WHILE @NDRKI < 10
update [npc2].[t_MERIT_grantBucket]
SET [grantBucketValue] =