|
Posted by Erland Sommarskog on 08/26/06 20:35
brm6546545 (russell.allbritain@gmail.com) writes:
> I have a tblTax. It has fields InvoiceNum, TaxAuthority, TaxableTotal,
> NonTaxableTotal, TaxCollected.
>
> Sample data
>
> 1,county,10.00,0.00,0.40
> 1,city,10.00,0.00,0.10
> 2,state,0.00,15.00,0.15
>
> When totaling invoice 1 should have totals of 10.00,0.00,0.50 because
> the 10.00 is the total for the invoice, but 0.50 is the total tax
> collected. I nee these totals in a report. In crystal reports i could
> just do a total on change of invoice number for the Taxable and
> nonTaxable Totals. but i have to this on an Access adp. I was hoping i
> could get a query to return something like
>
>
inv,auth,Taxable,nonTaxable,Collected,TaxableTot,NonTaxableTot,CollectedTot
> 1,county,10.00,0.00,0.40,10.00,0.00,0.50
> 1,city,10.00,0.00,0.10,10.00,0.00,0.50
> 2,state,0.00,15.00,0.15,0.00,15.00,0.15
SELECT InvoiceNum, TaxAuthority, TaxableTotal,
NonTaxableTotal, TaxCollected,
CollectedTot = SUM(TaxCollected) OVER (PARTITION BY InvoiceNum),
GrandCollected = SUM(TaxCollected) OVER ()
FROM tblTax
I did not include TaxabltTotal and NonTaxableTotal, since I don't really
see the point with them. Can the taxable amount be different for different
authorities? In such case, I don't know the business rules to compute
them.
The solution requires SQL 2005.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Navigation:
[Reply to this message]
|