0
Hello I’m not a programmer, just a curious developing a basic company system reports.
I wonder if I can use the values of a Where (invoiced bills) in another Where (orders made). I am grouping the orders made by sellers in a period and the invoiced notes of that seller in that same period, but this information is from different tables. I use a basic editor that runs within the system itself. I tried to poke around with variable declaration, but apparently it doesn’t accept the "@".
Below follows the procedure:
Select
a.vendedor,
a.NNotas,
a.VNotas,
b.NPed,
b.VPed
from(select s.vendedor, Count(s.saida_id) NNotas, sum(s.valorproduto) VNotas
from saida s
WHERE extract(month from S.DATA) = :pmes and extract (year from S.DATA) = :pano AND s.ativo='Y' AND S.natureza=0
group by s.vendedor) as A
Inner Join (select p.vendedor, Count(p.pedido_id) NPed,
sum(p.valorproduto) VPed
From pedido p
WHERE extract(month from P.DATA) = 11 and extract (year from P.DATA) =2020 and (p.tipovenda in ('00001','00004','00005','00011','00013'))
group by p.vendedor) As B On a.vendedor = b.vendedor
This way I get the results , but I need to put the month and the year 2 times...one for billing, another for orders.
I’ll be waiting for you. Thank you
you cannot repeat :pmes and :cloth?
– imex
I’m sorry ...I pasted the code with the values 11 and 2020...it was a test. In vdd what should have passed had pmes and cloth in the 2 Where. Then when I run...he asks me to put 2x the month and 2x the year.... The user can put different months and years. That for a future comparison may be useful. But at the time I need to load the same month and year
– Marcelo Vinicius
Which database and version is used?
– imex