I'm trying to create a table that uses an individual's date of birth to calculate their current age then use a CASE function to group by their age range. I'm not sure if this is the correct way to pull from a temporary column or not.
SELECT CASE
WHEN AGE < 18 then 'Under 18'
WHEN AGE between 18 and 30 then '18-30'
WHEN AGE > 30 then 'Over 30'
END as age_range
FROM Memberdata
WHERE
(SELECT
Year(BIRTH) as BirthYear,
Year(GETDATE()) as CurrentYear,
Year(GETDATE()) - YEAR(BIRTH) as 'Age'
FROM Memberdata)