Creating Age Bands in a query (1 Viewer)

CutAndPaste

Registered User.
Local time
Today, 22:41
Joined
Jul 16, 2001
Messages
60
I have a query that calculates Clients Ages in whole years. I want to be able to group my query output into a report grouped by age bands, say <16,16-20,21-30, >31 etc. and then be able to use the results of this in other groupings e.g. Gender by Age Band, or Favourite Fruit etc.

How can I create these age bands in a query? what's the SQL?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:41
Joined
Feb 19, 2002
Messages
43,486
Select IIf(ClientAge < 16, "Grp1 <16", IIf(ClientAge < 21, "Grp2 16-20", IIf(ClientAge < 30, "Grp3 21-30", "Grp4 >30"))) As AgeBand
From YourTable;

I included "Grpx " in front of each age band literal so that you could sort the data by age band and have them come out in ascending order.
 

CutAndPaste

Registered User.
Local time
Today, 22:41
Joined
Jul 16, 2001
Messages
60
Pat,

Worked a treat, many thanks!
 

Users who are viewing this thread

Top Bottom