• It's difficult to understand what you have problem with when you only describe the query rather than showing the code.

    But the query you posted can be simplified by adding another CTE:

    WITH cte AS (SELECT DATEDIFF(YEAR, c.DOB1,GETDATE()) AS AGE FROM ClientsDetails c),

    cte2 AS (

    SELECT CASE WHEN cte.Age < 30 THEN '18-29'

    WHEN cte.Age BETWEEN 30 AND 39 THEN '30-39'

    [...]

    ELSE '80+' END AS [Age]

    FROM cte

    )

    SELECT Age, COUNT(*)

    FROM cte2

    GROUP BY Age

    [font="Times New Roman"]Erland Sommarskog, SQL Server MVP, www.sommarskog.se[/font]