update @t set deducted_from_ot1 = case id when 1 then 0 when 2 then 4 when 3 then 22 end
update @t set deducted_from_ot2 = case id when 1 then 16 when 2 then 36 when 3 then 0 end
ot1 is overtime hours (monetary impact is greater)
ot2 is overtime hours (monetary impact is lesser)
due to some reasons we have deducted overtime hours (column "ot_deducted")
if we would have deducted seperately all was good but we deducted in a nutshell.
Now we need to figure out how much is deducted from ot1 and how from ot2.
1st row ot_deducted 16.
since we are giving priority to second ot hence the distribution will be
deducted_from_ot1 deducted from_ot2
0 16
No this is not math.
I can create a scalar function for this but that would fire each row. therfore I need case when statement to update columns "deducted from ot1" and "deducted_from_ot2)
Please explain overtime hours. here in US (generally speaking) work hours are 40 per week. What is overtime where you live or where you define overtime?
Also please explaing the following statement
ot1 = 26 is overtime hours (monetary impact is greater)
ot2 = 36 is overtime hours (monetary impact is lesser)
26 monetary impact is greater then 36? How is that possible? greater to who?
And quite ironically, there may be this row in acutal table.
1d=1
ot1=6
ot2=0
ot_deducted=8
Now you will how is possible to deduct 8 from 6.
Yes it is not possible.
This is not a question of what is right or what is wrong.
Due to some reason silly thing has happend and now we want to manage.
suppose its accounting
id1 = Johnson and philips
account1 has a ledger balance of 14
account2 has a ledger balance of 36
we receive a cheque of Rs 50(ot_deducted)
the updated ledger would now be
account1 = 0
account2=0
but how did account1 become 0, because we deducted rs.14
and how did account2 become 0 because we deducted rs 36
I want a tsql query which for 50 will give the result 14,36
Yes.
Now we are on right track.
Don't make the combination but look what is the balance of account1 and and account2
since account2 has balance 36 we can safely deduct 36 and account1 has balance 14 we can safely deduct 14.
If we receive cheque of rs 40 then
we can safely deduct 36 from account2
and 4 from account1
if we receive a cheque of rs 51 then
we can safely deduct 36 from account2
we cannot deduct 15 from account1 so we will deduct 14 (1 discarded)