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
| declare @ORDR table (docdate DATETIME, GrosProfit MONEY)
INSERT INTO @ORDR select '10/02/2009', 1
INSERT INTO @ORDR select '10/02/2009', 1
INSERT INTO @ORDR select '10/02/2009', 10
INSERT INTO @ORDR select '11/02/2009', 2
INSERT INTO @ORDR select '12/02/2009', 50
INSERT INTO @ORDR select '14/02/2009', 100
declare @OINV table (docdate DATETIME, GrosProfit MONEY)
INSERT INTO @OINV select '10/02/2009', 2
INSERT INTO @OINV select '11/02/2009', 10
INSERT INTO @OINV select '12/02/2009', 50
INSERT INTO @OINV select '15/02/2009', 100
select A.docdate,
(select SUM(T1.GrosProfit)
FROM @ORDR T1 WHERE T1.docdate = A.docdate) [montant commandé],
(select SUM(T2.GrosProfit)
FROM @OINV T2 WHERE T2.docdate = A.docdate) AS [montant facturé]
FROM
(
select distinct
ST1.docdate FROM @ORDR ST1
union
select distinct
ST2.docdate FROM @OINV ST2
) A |
Partager