I've got a fairly large SPROC I'm working on. Well, large as far as I am concerned since I haven't written SQL in quite some time. Anyway, I want to make this Update statement work:
update @salesCommission
set LineAmountWithCashDiscount = (LineAmount - ((LineAmount/ (
select SUM(LineAmount)
FROM @salesCommission
WHERE InvoiceNumber='00072766')) * CashDiscountAmount))
My problem is that I need to replace the:
WHERE InvoiceNumber='00072766'
clause so that the invoice number is not hard coded. Instead it should just be the invoice number of the current row being updated.
Can anyone show me how to re-write this update query so that it selects the sum of the LineAmount for the current row being updated?