T-SQL 中的 case 语句中断

break in case statement in T-SQL(T-SQL 中的 case 语句中断)

本文介绍了T-SQL 中的 case 语句中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 mssql 中的 case 语句中使用 break 命令?

Is possible using break command in case statement in mssql?

因为条件是验证表达式GO,而不是做下一个CASE的转换.ssip_miktar 为 5,ssip_teslim_miktar 为 0,S74MIKTAR 为 5

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

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

推荐答案

你不应该使用 break 因为 SQL Case 语句不会失败.

You shouldn't need to use a break because SQL Case statements don't fall through.

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

这篇关于T-SQL 中的 case 语句中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:T-SQL 中的 case 语句中断

基础教程推荐