• Many thanks to all that replied.

    I simplified the example to (hopefully) make it easy for others to help me. The code as originally written has the following WHERE clause:

    WHERE YEAR(h.HeaderDate) = YEAR(ReportEndingDate)

    Which should be ok for the aggregates in the CASE statement

    But the obvious problem here is what should YTD represent, if you have ReportStartingDate ReportEndingDate that are in different years? I have posed this question to management, and am awaiting a response.

    Lynn - I had initially tried putting all the codes in a single CTE as you did, but then in a "deer in headlights" moment, couldn't wrap my brain around how to differentiate the sets of codes when JOINing.

    All of the codes are unique in the source table, but on the client end, they are allowed to pick codes for the three sets. Then comma delimited strings of the three sets of codes are passed to the stored procedure that contains the code I posted.

    I am trying to determine if it is possible for the clients to select codes that might be duplicated among the three sets.

    Again my thanks to everyone. Sorry if what I posted was confusing --

    Best wishes,

    sqlnyc