• Certainly no way around the CASE but I might do it this way so as to only have to CASE it once.

    WITH SampleData (accountNumber, MaturityDate, ResetFreq, Amount) AS

    (

    SELECT 123 , '20140331' , '1D' ,100.00

    UNION ALL SELECT 123 , '20140331' , '1M' ,2400.00

    UNION ALL SELECT 123 , '20140331' , '' ,8700.00

    UNION ALL SELECT 123 , '20140331' , '1Y' ,-99.00

    UNION ALL SELECT 123 , '20140331' , '1M' ,299.00

    )

    SELECT accountNumber, MaturityDate

    ,ResetFreq=MAX(CASE rn WHEN 1 THEN ResetFreq END)

    ,Amount=SUM(Amount)

    FROM

    (

    SELECT *

    ,rn=ROW_NUMBER() OVER (PARTITION BY accountNumber, MaturityDate

    ORDER BY CASE ResetFreq

    WHEN '' THEN 1

    WHEN '1D' THEN 2

    WHEN '1M' THEN 3

    WHEN '3M' THEN 4

    WHEN '1Y' THEN 5

    WHEN '3Y' THEN 6

    WHEN '5Y' THEN 7

    WHEN '10Y' THEN 8

    END DESC)

    FROM SampleData

    ) a

    GROUP BY accountNumber, MaturityDate;


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St