gpt4 book ai didi

sql - 我可以在 WHILE 循环中使用 CASE 语句吗?

转载 作者:行者123 更新时间:2023-12-04 21:54:47 25 4
gpt4 key购买 nike

这就是我正在做的:

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

我收到此错误:

Incorrect syntax near the keyword 'CASE'.



不知道为什么。请帮忙!

最佳答案

对于您提出的建议,您应该使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com