需求:
根据 变量 @period_endtime 的不同值,设置相对应的 @end_type
@period_endtime | @end_type |
0331 | 1 |
0630 | 2 |
0930 | 3 |
1231 | 4 |
实现:
set @i_period = '20230331'; SET @period_endtime = RIGHT(@i_period, 4); SET @end_type = CASE @period_endtime WHEN "0331" THEN 1 WHEN "0630" THEN 2 WHEN "0930" THEN 3 WHEN "1231" THEN 4 END ;
标签:case,set,end,变量,WHEN,period,endtime From: https://www.cnblogs.com/bruce-he/p/17489235.html