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 语句中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)