我有问题 这是我的表项
Item |Begin | in01 | in02 | ..| in12 | out01 | out02 |..|out12 | Balance
A | 100 | 10 | 20 | ..| 10 | 5 | 10 |..| 5 | 110
项目 A 在第一个月的开始数量为 100,在第 12 个月的余额数量 = 110 余额每月更新
我需要调用一个过程来获取每个月报告的数据
sample for report for month 01
Beginning| In | Out | balance
100 | 10 | 5 | 105
sample for report for month 02
Beginning| In | Out | balance
105 | 20 | 10 | 115
sample for report for month 12
Beginning | In | Out | balance
balance month 11 | xx | xx | 11 + in - out
所以期初值=上月余额 有什么方法可以使这个存储过程简单吗?不使用很多“如果”
使用 case 更好?
需要一些想法..谢谢
最佳答案
你可以使用Case语句来避免if语句
select
case when beginning value = balance then 1st Option else 2nd Option as Test
from tblTest
关于sql-server - 解决 SQL if 条件的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32195268/