Reputation: 107
I have a problem this is my table item
Item |Begin | in01 | in02 | ..| in12 | out01 | out02 |..|out12 | Balance
A | 100 | 10 | 20 | ..| 10 | 5 | 10 |..| 5 | 110
item A have begin qty 100 at first month, and balance qty at month 12 = 110 balance updating every month
i need to call a procedure to get data for every month report
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
so beginning value = balance last month any way to make this stored procedure simple? not using a lot of 'IF'
it's better using case ?
need some idea.. thanks
Upvotes: 3
Views: 92
Reputation: 1746
If you have multiple conditions, it is better to use 'CASE', IF ELSE condition is only advisable to less conditions. like 2 to 3 conditions. If your conditional statements is more than 5 or 10, just use CASE WHEN to make your code more readable and easy to understand.
Regards.
Upvotes: 1
Reputation: 2196
u can used Case statement to avoid the if statement
select
case when beginning value = balance then 1st Option else 2nd Option as Test
from tblTest
Upvotes: 1