I have the following query.
Select x1.TotalAmount, [ReturnTaxAmount](x1.TotalAmount,@TaxRate) AS TaxAmount,
x2.DocumentType
FROM table1 X1
INNER JOIN table2 x2 on t1.id = t2.t1id
Now how do I get the running total of self-declared TaxAmount? I wish to do something like this
Select x1.TotalAmount,
SUM([ReturnTaxAmount](x1.TotalAmount,@TaxRate) AS TaxAmount) OVER (PARTITION BY x3.InvId
ORDER BY x3.createddate
ROWS BETWEEN UNBOUNDED PRECEDING
AND 1 PRECEDING) AS TaxAmount,
x2.DocumentType
FROM table1 X1
INNER JOIN table2 x2 on t1.id = t2.t1id
[ReturnTaxAmount] is a function that will return calculated decimal value.
This is the method I tried but failed which suspected is because of the table hasn't really being generated yet.
Is it possible to do so or must I create a new declared/temp table to store the table and select the table again to get the running total of it.