Add values of different selects

1

Good morning To everyone, I have two select, I'm displaying next to each other, I need to add the value of a select with that of the other .. is it possible? the two select are separate tables, I'm displaying one value next to the other, but I need to add those values ... please if anyone knows I need help. follow the code of the select:

Set objConn =  Server.CreateObject("ADODB.Connection")
objConn.Open "DBQ=" & Server.MapPath("banco.mdb") & ";Driver={Microsoft Access Driver (*.mdb)}","username","password"
strQ = "SELECT * FROM Vendas2017 ORDER BY id asc"
Set ObjRs = objConn.Execute(strQ)


Set objConn2 =  Server.CreateObject("ADODB.Connection")
objConn2.Open "DBQ=" & Server.MapPath("banco.mdb") & ";Driver={Microsoft Access Driver (*.mdb)}","username","password"
strQ2 = "SELECT * FROM Vendas2018 ORDER BY id asc"
Set ObjRs2 = objConn2.Execute(strQ2)
    
asked by anonymous 09.02.2018 / 11:16

2 answers

2

You can add directly to the bank using a third query , which would look like this:

select sum(janvalor) as Soma from 
(
     select sum(janvalor) janvalor from Vendas2017 
     union
     select sum(janvalor) janvalor from Vendas2018 
) as Vendas

Or add in code, but then you need a loop for or foreach to read the records and add.

    
09.02.2018 / 12:48
0

I usually do this with a certain strategy. Easier to show than to explain. Suppose I want to compare sales for different years month to month:

select mes, sum(iif(ano = 2017, valor, 0)) Ex2017, sum(iif(ano = 2018, valor, 0)) Ex2018 from vendas group by mes;

    
10.02.2018 / 16:11