I need to summate across a number of line items over a group of invoices, then round down on an invoice by invoice basis to the nearest penny.
I would then like to get a total of THOSE rounded values.
Does my sql need to return the items, and i then manually summate these values by reading each one by one, or can I do this in the sql. Remember, I still need to round on an invoice by invoice basis.
My sql which returns rounded invoice totals is given below:
SELECT
SUM(FLOOR(sii.u nitPrice*sii.Qt y)) AS total
FROM salesinvoiceIte m sii,
salesinvoice si
WHERE sii.invoiceId = si.invoiceId
GROUP BY si.InvoiceId
;
This returns a number of rows which I then need a total for: is there an elegant way of achieving this in sql server in a query?
I would then like to get a total of THOSE rounded values.
Does my sql need to return the items, and i then manually summate these values by reading each one by one, or can I do this in the sql. Remember, I still need to round on an invoice by invoice basis.
My sql which returns rounded invoice totals is given below:
SELECT
SUM(FLOOR(sii.u nitPrice*sii.Qt y)) AS total
FROM salesinvoiceIte m sii,
salesinvoice si
WHERE sii.invoiceId = si.invoiceId
GROUP BY si.InvoiceId
;
This returns a number of rows which I then need a total for: is there an elegant way of achieving this in sql server in a query?
Comment