Hi:
QUESTION 1
I have to update some fields of a table of access according to the value of parameter. If this paramter is "true" I need to update.
Table
idInvoice
price
percentageTax1
tax1
percentageTax2
tax2
total
Example values:
idinvoice: 12300
price: 100 €
percentageTax1: 10 %
tax1= 10€
percentageTax2: 5 %
tax2: 5€
total: 115 € (result: 100€+10€+5€)
Ok. If the parameter on that I have commented before is "true" I must update the percentages and then update the total. I need to replace the "old" percentages by new percent.
Ok I can do it in 3 queries:
update invocies set percentageTax1=20,tax1=price *(percentageTax1/100) where idInvoice=@number and percentageTax1=10
update invocies set percentageTax2=7,tax2=price *(percentageTax2/100) where idInvoice=@number and percentageTax2=5
update invocies set total=price+tax1+tax2 where idInvoice=@number
. But my question is:
is there any an alternative to do this in 1 query?
QUESTION 2
Other question about update.
If I have 2 linked tables
EXAMPLE TABLE INVOICE
idInvoice
total
EXAMPLE TABLE DETAIL
idInovice
Line
price
The "total" field is the total sum of the field "price" of the table "detail"
how it would be the "query" to update "total" field?
TOTAL field need to be stored in database
SOLUTION QUESTION 2:
is possible if I do this query. Example.
update table1 INNER JOIN table2 ON table1.id=table2.id set table1.field1=table2.fieldX