declare @LigneVide int declare @LigneTotalVide int select Rv_CodePlanif, count(*) as NbLigneTotal into #TempTotal from CLI_Gestion_Articles.T_UTIL_REVERSEMENTS where datediff(day,Rv_DateDemande,getdate()) >= 7 group by Rv_CodePlanif select Rv_CodePlanif, count(*) as NbLigneVide into #TempVide from CLI_Gestion_Articles.T_UTIL_REVERSEMENTS where datediff(day,Rv_DateDemande,getdate()) >= 7 and Rv_DateAcceptation is NULL group by Rv_CodePlanif select a.Rv_CodePlanif, cast(NbLigneVide/NbLigneTotal as float) as Ratio from #TempTotal a,#TempVide b where a.Rv_CodePlanif = b.Rv_CodePlanif