• Here is another way that might work for you.

    CREATE TABLE #Table_1

    (

    [Doc] [varchar](50) NULL,

    [Prodtype] [varchar](50) NULL,

    [TERM] [int] NULL,

    [Yr] [int] NULL,

    [MTH] [int] Null

    )

    INSERT INTO #Table_1

    Select DOC, PRODTYPE,TERM,

    CASE TERM

    WHEN 1 THEN COUNT(CAST(TERM AS INT))

    ELSE 0

    END as 'YR',

    CASE TERM

    WHEN 12 THEN COUNT(CAST(TERM AS INT))

    ELSE 0

    END AS 'MTH'

    FROM TABLE_1

    GROUP BY DOC, PRODTYPE,TERM

    SELECT Doc, Prodtype, SUM(YR) AS 'YR', SUM(Mth) AS 'Mth', SUM(Yr + MTH) AS 'Gtotal'

    FROM #Table_1

    GROUP BY Doc, Prodtype

    DROP TABLE #Table_1

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]