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 49 50 51 52 53 54 55 56 57 58 59 60 61
|
/****** Script de la commande SelectTopNRows à partir de SSMS ******/
DECLARE @D1 AS smalldatetime
DECLARE @D2 AS smalldatetime
SET @D1 = CONVERT(smalldatetime,'01/10/2012',103)
SET @D2 = CONVERT(smalldatetime,'30/09/2014',103)
SELECT T1.[CT_NUM]
,(YEAR(DO_Date)-2000)*100+MONTH(DO_date)
,MIN(T3.CatégorieClient) AS CatégorieClient
,T3.FournitLePapier
,T3.OrganiseLeTransport
,CONVERT(money,SUM(T1.[DL_MontantHT])) AS [CA_Total]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V000_MARGE','V001_NOTE','V002_REMISE','V003_RFA','V004_REDRESSTVA','V005_INTERETRETARD','V006_COMMISSIONS') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [V00xxxx]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V101_TRAIT_FICH','V102_IMP_CROMALIN','V104_AUTRES','V105_CERTIF_FICHIE') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [PréPresse]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V201_CALAGE_ROT','V202_ROULE_ROT','V203_REPIQ_ROT','V204_PANTONE_ROT') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [ImpRoto]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V301_CALAGE_FEUIL','V302_ROULE_FEUIL','V303_REPIQ_FEUIL','V304_PANTONE_FEUIL','V305_VERNIS_MACH') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [ImpFeuil]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V205_VERNIS_UV_ROT','V306_VERNISSTEIHNM') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [VernisSIB]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V360_STT_VERNIS') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [VernisSTT]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V558_PELLICUL_STT') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [PellicSTT]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V209_PAPIER_ROT','V210_PAP_ROT_MILLE','V219_PAP_ROT_CLI') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [PapierRoto]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V309_PAPIER_FEUILL','V310_PAP_FEU_MILLE','V319_PAP_FEU_CLI') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [PapierFeuil]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V460_PAPIER_NUM') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [PapierNumérique]
,CONVERT(money,SUM(CASE WHEN T11.FA_CodeFamille ='ADHESIFS' THEN T1.[DL_MontantHT] ELSE 0 END)) AS [CA_ADHESIFS]
,CONVERT(money,SUM(CASE WHEN T11.FA_CodeFamille ='BOBINES' THEN T1.[DL_MontantHT] ELSE 0 END)) AS [CA_BOBINES]
,CONVERT(money,SUM(CASE WHEN T11.FA_CodeFamille ='PLAQUES' THEN T1.[DL_MontantHT] ELSE 0 END)) AS [CA_PLAQUES]
,CONVERT(money,SUM(CASE WHEN T11.FA_CodeFamille ='LAMINATION' THEN T1.[DL_MontantHT] ELSE 0 END)) AS [CA_LAMINATION]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V251_STT_IMP_ROTO','V351_STT_IMP_FEUIL') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [ImpSTT]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V401_CALAGE_NUM','V402_PASS_4C_NUM','V403_PASS_2C_NUM','V404_PASS_1C_NUM') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [ImpNumérique]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V410_CALAGE_SHARP','V411_A3_NOIR','V411_SHARP_QUADRI','V412_A3_QUADRI','V412_SHARP_NB','V413_A4_QUADRI','V414_A3_R/V_QUADRI') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [ImpSharp]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V420_CALAGE_VUTEK','V421_IMP_VUTEK') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [GdFormatVutek]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V430_CALAGE_HP_TRA','V431_IMP_HP_TRACEU') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [GdFormatHP]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V440_CALAGE_SEIKO','V441_IMP_SEIKO') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [GdFormatSeiko]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V561_STT_GD_FORMAT') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [GdFormatSTT]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V103_COMPO_PAO','V450_TRAIT_FICH','V451_IMP_CROMALIN','V452_COMPO_PAO','V453_AUTRES','V454_CERTIF_FICHIE') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [PaoSGB]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V455_FACONNAGE_NUM') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [FaçoNum]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V501_COUPE','V502_PLIAGE','V505_RAINAGE','V506_PERFORATION','V560_FORME_DECOUPE') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [FaçoSIB]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V503_ENC_PIQ','V504_DOS_CARRE_COL','V507_FACONNAGE_NUM') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [ReliureSIB]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V510_MO_FINITION','V800_POSE_SIB') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [PoseSIB]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V551_COUPE_STT','V552_PLIAGE_STT') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [FaçoSTT]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V553_EN_PIQ_STT','V554_DCC_STT','V555_DCCOUSU_STT','V556_DCPUR_STT','V557_RELIURE_STT','V559_DIVERS_STT') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [ReliureSTT]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V601_ENCDOC','V602_MIS_S/FILM','V603_ADRESS') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [M/Film&EncartageSIB]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V604_AFFRANCH','V605_AFFRANCHTVA') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [Affranchissement]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V651_ENCDOC_STT','V652_MS/FILM_STT','V653_ADRESS_STT') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [M/Film&EncartageSTT]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V701_COND_CARTON','V702_COND_S/FILM','V703_COND_PALET','V704_BOITE_CRYSTAL') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [ConditionnementSIB]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V751_COND_CART_STT','V752_COND_S/FILM_S','V753_COND_PALET_ST') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [ConditionnementSTT]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V508_LIVRAISON_CLT','V902_TRANSP_MESSAG','V903_TRANSP_STT','V904','V912_TRANSP_MESSAG') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [Transport]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V901_TRANSP_CHRONO') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [TransportChrono]
,CONVERT(money,SUM(CASE WHEN T1.AR_Ref IN ('V0_DESCRIPTION','V511') THEN T1.[DL_MontantHT] ELSE 0 END)) AS [Autres]
,MIN(T2.CO_Nom)
FROM [SIB].[dbo].[F_DOCLIGNE] AS T1
LEFT JOIN [SIB].[dbo].[F_ARTICLE] AS T11 ON T11.AR_Ref=T1.AR_Ref
LEFT JOIN [SIB].[dbo].[F_COLLABORATEUR] AS T2 ON T2.CO_No=T1.CO_No
LEFT JOIN [DBSIB].[dbo].ComplémentsF_COMPTET AS T3 ON T3.CT_Num=T1.[CT_NUM]
WHERE T1.[DO_Domaine]=0 AND T1.[DO_Type] IN (6,7)
AND T1.DO_Date BETWEEN @D1 AND @D2
AND T1.CO_No>0 AND T1.CO_No<>19
AND T1.CT_Num NOT LIKE '41VALPACOS%'
GROUP BY (YEAR(DO_Date)-2000)*100+MONTH(T1.DO_date),T1.CT_NUM,T3.FournitLePapier,T3.OrganiseLeTransport
ORDER BY SUM(T1.[DL_MontantHT]) DESC |
Partager