We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question

base simple calculation queries [closed]

asked 2017-05-07 20:11:00 +0200

Avvy65 gravatar image

updated 2021-05-23 11:28:09 +0200

Alex Kemp gravatar image

I have a couple of Access databases which have caculation queries, and I am finding that it is not that simple in base. For example, I want to calculate the vat amount on an item price, so I tried this: VAT AS "'Cost' *0.2" , but it doesn't work. Cost is say £29.95, so what is the vat payment of 20 percent.

I have looked at the HSQL manual for this and it only describes more complex queries with multiple fields, and I have tried similar SQL code but for my needs to no joy.

@librebel, I did try that earlier and it gave me a syntax error.

@EasyTrieve, thank you that has done the job for me. Yes, the manual is good if you know where to look.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2021-05-23 11:28:46.891794


hello Avvy65, assuming that "Cost" is a field in your table you could try: "Cost" * 0.2 AS VAT

librebel gravatar imagelibrebel ( 2017-05-07 20:20:59 +0200 )edit

2 Answers

Sort by » oldest newest most voted

answered 2017-05-07 21:48:42 +0200

EasyTrieve gravatar image

In HSQLDB 1.8 (the default embedded database):

 SELECT "Product ID", "Cost", "Cost" * .2 AS "VAT" FROM "Products"
edit flag offensive delete link more

answered 2017-05-07 21:18:52 +0200

Avvy65 gravatar image

Thanks but I am getting syntax errors with using that in SQL, and yes "Cost" is a field .

edit flag offensive delete link more


Hi @Avvy65, thanks for the question. Please put your comments and updates in your original question by editing it, or in other attached comments, but not in an answer box as you have done here. The idea is that others can search for your same question and possibly find answers. If they find more questions as answers that doesn't help anyone. K? Thanks.

EasyTrieve gravatar imageEasyTrieve ( 2017-05-07 21:56:20 +0200 )edit

What is the syntax error? Your VAT AS "'Cost' *0.2" should be "Cost" * 0.2 AS "VAT" - wrong order and punctuation. The sample from @EasyTrieve works for me.

peterwt gravatar imagepeterwt ( 2017-05-08 11:51:54 +0200 )edit

Question Tools

1 follower


Asked: 2017-05-07 20:11:00 +0200

Seen: 289 times

Last updated: May 08 '17