Refresh request (access & vb.net)

QUESTION 1

I need to update some fields of the access table according to the parameter value. If this parameter is true, I need to update.

Table

idInvoice

Price

percentageTax1

tax1

percentageTax2

tax2

General

Example values:

idinvoice: 12300

price: 100 €

percentTax1: 10%

tax1 = 10 €

percentTax2: 5%

tax2: 5 €

total: 115 € (result: 100 € + 10 € + 5 €)

Ok If the parameter I commented on earlier is "true", I have to update the percentages and then update the total. I need to replace the "old" interest with a new percentage.

Ok, I can do this 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 an alternative for this in 1 request?

QUESTION 2

Another update question.

If I have 2 related tables

EXAMPLE TABLE ACCOUNT

idInvoice

General

idInovice

"total" - "" ""

"" "" ?

TOTAL


2:

, . .

1 INNER JOIN table2 ON table1.id = table2.id set table1.field1 = table2.fieldX

+3
3

, .

update invocies 
set percentageTax1 = IIf(percentageTax1=10, 20, percentagetax1)
 , percentageTax2 = IIf(percentageTax2=5, 7, percentageTax2)
where idInvoice=@number AND (percentageTax1=10 OR percentageTax2=5)
+1

. - , , - .

, StackOverflow, , .

+2

Most often, you pull out the invoice you want to work on, do the math in the code to update the values, and then return all the updated values ​​to the database in one go.

There are thousands of ways to do it!

perhaps one place to start is http://code.msdn.microsoft.com/eisk

or here http://www.asp.net/data-access/tutorials/an-overview-of-inserting-updating-and-deleting-data-vb

+1
source

Source: https://habr.com/ru/post/1746168/


All Articles