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 48
|
CREATE PROCEDURE [sc_edition].[Journaux_Centralisateurs]
@Date datetime,
@Per smallint
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT M.MVT_JNL, J.JNL_INT, J.JNL_CPT, M.MVT_GEN, G.GEN_INT, H.CUMUL_DB, H.CUMUL_CR,
ABS(SUM(CASE
WHEN MVT_MNT < 0
THEN MVT_MNT
ELSE 0
END))AS SLD_DB,
SUM(CASE
WHEN MVT_MNT > 0
THEN MVT_MNT
ELSE 0
END)AS SLD_CR
FROM D_MVT AS M
INNER JOIN D_GEN AS G
ON G.GEN_NUM = M.MVT_GEN
INNER JOIN D_JNL AS J
ON J.JNL_NUM = M.MVT_JNL
LEFT OUTER JOIN (SELECT MVT_JNL,
ABS(SUM(CASE WHEN MVT_MNT < 0 THEN MVT_MNT ELSE 0 END))AS CUMUL_DB,
SUM(CASE WHEN MVT_MNT > 0 THEN MVT_MNT ELSE 0 END)AS CUMUL_CR
FROM D_MVT
WHERE(MVT_DATE <= @Date) AND (MVT_PER = @Per)
GROUP BY MVT_JNL) AS H
ON H.MVT_JNL = M.MVT_JNL
WHERE (MVT_DATE <= @Date) AND (MVT_PER = @Per)
GROUP BY M.MVT_JNL, J.JNL_INT, J.JNL_CPT, M.MVT_GEN, G.GEN_INT, H.CUMUL_DB, H.CUMUL_CR
HAVING ABS(SUM(CASE
WHEN MVT_MNT < 0
THEN MVT_MNT
ELSE 0
END)) <> 0
OR SUM(CASE
WHEN MVT_MNT > 0
THEN MVT_MNT
ELSE 0
END) <> 0
ORDER BY M.MVT_JNL, M.MVT_GEN
END |
Partager