Is possible using break command in case statement in mssql?
可以在mssql的case语句中使用break命令吗?
Because the condition is verified that expression GO
, instead of doing the next CASE's transition. ssip_miktar is 5, ssip_teslim_miktar is 0 and S74MIKTAR is 5
因为条件验证表达式GO,而不是做下一个CASE的转换。 ssip_miktar是5,ssip_teslim_miktar是0,S74MIKTAR是5
update set ssip_teslim_miktar= ssip_teslim_miktar+
CASE WHEN ssip_miktar<@S74MIKTAR AND ssip_teslim_miktar=0 THEN @S74MIKTAR-ssip_miktar
WHEN ssip_miktar<@S74MIKTAR AND ssip_teslim_miktar>0 THEN @S74MIKTAR-(ssip_miktar+ssip_teslim_miktar)
WHEN ssip_miktar=@S74MIKTAR AND ssip_teslim_miktar=0 THEN @S74MIKTAR
WHEN ssip_miktar=@S74MIKTAR AND ssip_teslim_miktar>0 THEN @S74MIKTAR-ssip_teslim_miktar
WHEN ssip_miktar>@S74MIKTAR AND ssip_teslim_miktar=0 THEN @S74MIKTAR
WHEN ssip_miktar>@S74MIKTAR AND ssip_teslim_miktar>0 THEN @S74MIKTAR
END,
@S74MIKTAR=@S74MIKTAR-CASE
WHEN ssip_miktar<@S74MIKTAR AND ssip_teslim_miktar=0 THEN @S74MIKTAR-ssip_miktar
WHEN ssip_miktar<@S74MIKTAR AND ssip_teslim_miktar>0 THEN @S74MIKTAR-(ssip_miktar+ssip_teslim_miktar)
WHEN ssip_miktar=@S74MIKTAR AND ssip_teslim_miktar=0 THEN @S74MIKTAR
WHEN ssip_miktar=@S74MIKTAR AND ssip_teslim_miktar>0 THEN @S74MIKTAR-ssip_teslim_miktar
WHEN ssip_miktar>@S74MIKTAR AND ssip_teslim_miktar=0 THEN @S74MIKTAR
WHEN ssip_miktar>@S74MIKTAR AND ssip_teslim_miktar>0 THEN @S74MIKTAR
ELSE 0
END
where ssip_teslim_miktar<ssip_miktar
3 个解决方案
#1
8
You shouldn't need to use a break
because SQL Case statements don't fall through.
您不应该使用中断,因为SQL Case语句不会失败。
DECLARE @x int
SET @x = 0
SELECT CASE
WHEN @x = 0 THEN 'zero' -- Only this line of the expression is evaluated
WHEN @x <> 0 THEN 'not-zero'
END
#2
5
This is transactional SQL and is not iterative. It does not require a break because only one of the when/else clauses will be evaulated.
这是事务性SQL,不是迭代的。它不需要中断,因为只会调用其中一个when / else子句。
Try the following:
请尝试以下方法:
declare @test int
set @test=1
select @test = @test +
case
when 1=1 then 1
when 2=2 then 1
when 3=3 then 1
when 4=4 then 1
when 5=5 then 1
when 6=6 then 1
when 7=7 then 1
when 8=8 then 1
else 1
end
select @test
@test
is only ever 2
@test只有2
#3
4
This is not necessary. THEN
effectively acts as a return or break, so the statement is short-circuited.
这不是必要的。然后这有效地作为回报或休息,因此该陈述被短路。
#1
8
You shouldn't need to use a break
because SQL Case statements don't fall through.
您不应该使用中断,因为SQL Case语句不会失败。
DECLARE @x int
SET @x = 0
SELECT CASE
WHEN @x = 0 THEN 'zero' -- Only this line of the expression is evaluated
WHEN @x <> 0 THEN 'not-zero'
END
#2
5
This is transactional SQL and is not iterative. It does not require a break because only one of the when/else clauses will be evaulated.
这是事务性SQL,不是迭代的。它不需要中断,因为只会调用其中一个when / else子句。
Try the following:
请尝试以下方法:
declare @test int
set @test=1
select @test = @test +
case
when 1=1 then 1
when 2=2 then 1
when 3=3 then 1
when 4=4 then 1
when 5=5 then 1
when 6=6 then 1
when 7=7 then 1
when 8=8 then 1
else 1
end
select @test
@test
is only ever 2
@test只有2
#3
4
This is not necessary. THEN
effectively acts as a return or break, so the statement is short-circuited.
这不是必要的。然后这有效地作为回报或休息,因此该陈述被短路。