Home Forums SQL Server 2008 SQL Server 2008 - General query tuning (PFA, execution plan and indexed view)- need help to enhance performance RE: query tuning (PFA, execution plan and indexed view)- need help to enhance performance

  • saxena200 (2/6/2013)


    @Chris

    PFA the execution Plan...

    this is not working.... ๐Ÿ™

    Apologies, I missed a column from the GROUP BY:

    SELECT DT.MO_OF_YR_NM [Month],

    DT.MO_OF_YR[month_No],

    DT.YR[Year],

    DT.MIC_WK_OF_MO_NM [Week],

    DT.DT [Date],

    cstmr.[Organisation],

    cstmr.CSTMR_KEY,

    cstmr.CNTRCT_DD, -- NEW

    PD.BS_LN_NM [Business Line],

    ED.EMPE_NM [Sales Executive],

    cstmr.[Total no of Lines],

    [Total No Of Unpaid Lines] = CASE WHEN cstmr.[Total Amount Due] > 0 THEN cstmr.[Total no of Lines] ELSE 0 END,

    cstmr.[Total Amount Due]

    FROM DT_DIM DT

    INNER JOIN (

    SELECT

    CDBF.FCT_DT_KEY,

    [Organisation]= CD.CSTMR_NM,

    cd.CSTMR_KEY,

    [Total no of Lines] = COUNT(DISTINCT CDBF.CSTMR_KEY),

    cdbf.ar_bhvr_key,

    [Total Amount Due]= SUM(CDBF.BLNC),

    CDBF.CNTRCT_DD -- NEW

    FROM CSTMR_DUE_BLNC_FCT CDBF

    INNER JOIN CSTMR_DIM CD

    ON CD.CSTMR_KEY = CDBF.CSTMR_KEY --

    GROUP BY

    CDBF.FCT_DT_KEY,

    CD.CSTMR_NM,

    cd.CSTMR_KEY,

    cdbf.AR_BHVR_KEY,

    CDBF.CNTRCT_DD -- NEW

    ) cstmr ON DT.DT_KEY = cstmr.FCT_DT_KEY

    Inner join AR_BHVR_DIM ABD

    on ABD.AR_BHVR_KEY = cstmr.AR_BHVR_KEY

    Inner join PD_DIM PD

    on PD.PD_KEY = ABD.PD_KEY

    Inner Join EMPE_DIM ED

    ON ED.EMPE_KEY=ABD.EMPE_KEY

    WHERE DT.DT>=@FromDate AND DT.DT<=@ToDate

    /*

    GROUP BY

    DT.MO_OF_YR_NM,

    DT.MO_OF_YR,

    DT.MIC_WK_OF_MO_NM,

    DT.DT,

    DT.YR,

    CD.CSTMR_NM,

    PD.BS_LN_NM,

    ED.EMPE_NM,

    --CDBF.FCT_DT_KEY,

    CDBF.AR_BHVR_KEY,

    CDBF.CNTRCT_DD,

    cd.CSTMR_KEY

    */

    ORDER BY DT.MO_OF_YR

    OPTION (EXPAND VIEWS)

    โ€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.โ€ - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden