on 2015 May 31 6:14 AM
I have a trigger that logs the customer order changes in a table. I shall, for each row in the log table to figure out how much the value has changed. I have three columns to be used, quantity, price and discount.
In the table, the three columns like this:
old_price, new_price, old_qty, new_qty, old_discount, new_discount.
Everything works except that I do not get into how I can calculate the amount of change per row. Each entry in the table is logged in the field operation if there is a change, removal, or new row. 1 = New row, 2 = Change 3 = Removal.
I do like this below now, it works if you just make one change. If you make two changes or more on the same row, for example, the number and price, it does not work. Even if there are no changes at all on these three fields it dont work. What I have done is wrong, so the question is how I will do it right?
(new_qty - old_qty) as cc_qty,
(new_price - old_price) as cc_price,
(new_discount - old_discount) as cc_discount,
(case when cc_qty = 0 Then old_qty else cc_qty end *
case when cc_price = 0 Then old_price else cc_price end *
ucase when cc_discount = 0 Then (1-old_discount/100) else ( case when ol_operation = 1 then (1-cc_discount/100) else (- cc_discount /100) end ) end ) as cc_amount,
Request clarification before answering.
I may not have understood your question fully, but would it not be simply like that (possibly rounded as required)?
cc_amount =
isnull(new_price * new_qty * (1 - new_discount / 100.0), 0)
- isnull(old_price * old_qty * (1 - old_discount / 100.0), 0);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
53 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.