How do you write a SQL query to calculate the VAT and then add it to Total?
Thank You
How do you write a SQL query to calculate the VAT and then add it to Total?
Thank You
Surely homework.
However, let us know what you've tried. In general, you're supposed to make an effort first before people on SO will help you.
What does your table look like? How is the total calculated? What query returns the total? What do you need to do to the total to add tge VAT?
Paul
SELECT SUM(value) as SubTotal,
SUM(value * 0.15) as VAT,
SUM(value) + SUM(value * 0.15) as GrandTotal
FROM <recordsource>
WHERE <filterclause>
The result is a single row recordset containing:
The bits you will need to fill in are:
Note that the last value, GrandTotal, can be calculated outsite the query, by simply adding SubTotal and VAT. Depending upon the application and it's use, there may also be a requirement to determine at a per-item level whether tax is to be levied or not (some items are legally except from tax).
If, however, you need an itemised invoice, you're better off returning each row, and calculating the VAT in your application code, so that you can output the item, unit cost, number of units, etc.