1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| CREATE FUNCTION acReliquat3
(@TYPE int)
RETURNS TABLE
AS
RETURN
SELECT R2.CleProduit
, P.Designation
, SUM(R2.SumQteLiee) AS SumQtesLiee
, SUM(R2.PremierDeQuantite) AS SumQteSource
, SUM(R2.PUNetHTS) AS PUNetsHTS
, SUM(R2.PrixNetTTCS) AS PUNetsTTCS
, SUM(R2.PUNetHTD) AS PUNetsHTD
, SUM(R2.PUNetTTCD) AS PUNetsTTCD
, T.TiersRaisonSociale AS TiersRaisonSocialeS
, P.Code AS CodeProduit
, P.Reference AS ReferenceProduit
, P.Designation2
, P.Quantite AS QteProduit
, P.FamilleArticle
, P.Emplacement
, P.StatutLot
, P.Marque
, P.CategorieProduit
, (SUM(R2.SumQteLiee) - SUM(R2.PremierDeQuantite)) * -1 AS Ecart
, SUM(R2.PUNetHTS) - SUM(R2.PUNetHTD) AS EcartHT
, SUM(R2.PrixNetTTCS) - SUM(R2.PUNetTTCD) AS EcartTTC
, (SUM(R2.SumQteLiee) * 100) / SUM(R2.PremierDeQuantite) AS Realispour
FROM dbo.AcReliquat2(@TYPE) AS R2
LEFT JOIN dbo.acProduit AS P
ON R2.CleProduit = P.CleProduit
LEFT JOIN dbo.acEffet AS E
ON R2.CleEffetS = E.CleEffet
LEFT JOIN dbo.acTiers AS T
ON E.CleTiers = T.CleTiers
GROUP BY R2.CleProduit
, P.Designation
, T.TiersRaisonSociale
, P.Code
, P.Reference
, P.Designation2
, P.Quantite
, P.FamilleArticle
, P.Emplacement
, P.StatutLot
, P.Marque
, P.CategorieProduit
, E.Code |
Partager