Bonjour,
Je souhaite faire une requête qui donne le résultat de 2 requêtes :
J'ai la première requête qui me donne les besoins de matière pour le mois choisi
select PARACALC.ValParaAlpha13 'Ref chant',
sum(case when PARACALC.ValParaAlpha1 In ('TOTAL') OR PARACALC.ValParaAlpha2 In ('TOTAL') OR PARACALC.ValParaAlpha3 In ('TOTAL') OR PARACALC.ValParaAlpha4 In ('TOTAL') then
(PARACALC.ValParaNum1+PARACALC.ValParaNum2)*2/1000 else
case when PARACALC.ValParaAlpha1 In ('Chant ALU','Chant PVC') then PARACALC.ValParaNum1/1000 else 0 end +
case when PARACALC.ValParaAlpha2 In ('Chant ALU','Chant PVC') then PARACALC.ValParaNum1/1000 else 0 end +
case when PARACALC.ValParaAlpha3 In ('Chant ALU','Chant PVC') then PARACALC.ValParaNum2/1000 else 0 end +
case when PARACALC.ValParaAlpha4 In ('Chant ALU','Chant PVC') then PARACALC.ValParaNum2/1000 else 0 end
end *1.2) as 'Conso du mois'
from paracalc
join COMC on PARACALC.CodeTableParametre=comc.CodeTableParametre
join COME on comc.NoAccuseRecepto=come.NoAccuseReception
where come.AnneeSouhPlusTard=2017 and datepart(mm,come.DateSouhaiteePlustard)=6 and (PARACALC.ValParaAlpha13 like ('PVC%') or PARACALC.ValParaAlpha13 like ('ABS%'))
group by paracalc.ValParaAlpha13
order by PARACALC.ValParaAlpha13 desc
et j'ai la 2 requête qui me donne le besoin futur :
select PARACALC.ValParaAlpha13 'Ref chant'
,sum(case when PARACALC.ValParaAlpha1 In ('TOTAL') OR PARACALC.ValParaAlpha2 In ('TOTAL') OR PARACALC.ValParaAlpha3 In ('TOTAL') OR PARACALC.ValParaAlpha4 In ('TOTAL') then
(PARACALC.ValParaNum1+PARACALC.ValParaNum2)*2/1000 else
case when PARACALC.ValParaAlpha1 In ('Chant ALU','Chant PVC') then PARACALC.ValParaNum1/1000 else 0 end +
case when PARACALC.ValParaAlpha2 In ('Chant ALU','Chant PVC') then PARACALC.ValParaNum1/1000 else 0 end +
case when PARACALC.ValParaAlpha3 In ('Chant ALU','Chant PVC') then PARACALC.ValParaNum2/1000 else 0 end +
case when PARACALC.ValParaAlpha4 In ('Chant ALU','Chant PVC') then PARACALC.ValParaNum2/1000 else 0 end
end *1.2) 'Besoin'
from paracalc
join COMC on PARACALC.CodeTableParametre=comc.CodeTableParametre
join COME on comc.NoAccuseRecepto=come.NoAccuseReception
where come.AnneeSouhPlusTard=2017 and datepart(mm,come.DateSouhaiteePlustard)>6 and (PARACALC.ValParaAlpha13 like ('PVC%') or PARACALC.ValParaAlpha13 like ('ABS%'))
group by paracalc.ValParaAlpha13,COME.AnneeSouhPlusTard
order by PARACALC.ValParaAlpha13 desc
Le problème est que je ne sais pas comment réunir les 2 requêtes pour avoir un résultat du type :
Ref chant Conso du mois Besoin
Chant 1 10 20
chant 2 15
chant 3 5 0
Si quelqu'un peux m'aider
Merci.