这就是我在做什么:

while (@counter < 3 and @newBalance >0)
begin
CASE
when  @counter = 1 then  ( @monFee1 = @monthlyFee, @newBalance = @newBalance-@fee)
when  @counter = 2 then  ( @monFee2 = @monthlyFee, @newBalance = @newBalance-@fee)
END
@counter = @counter +1
end

我收到此错误:



不知道为什么。请帮忙!

最佳答案

对于您的建议,应该使用IF语句

While (@counter < 3 and @newBalance >0)
Begin
    If @Counter = 1 Then
        Begin
            Set @monFee1 = @monthlyFee
            Set @newBalance = @newBalance-@fee
        End

    If @Counter = 2 Then
        Begin
            Set @monFee2 = @monthlyFee
            Set @newBalance = @newBalance-@fee
        End

    Set @counter = @counter +1
End

关于sql - 我可以在WHILE循环中使用CASE语句吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2915883/

10-09 01:57