MS Access + SQL - Left join on switch statement?
I have a switch statement in a crosstab query:
Switch([Age]<20, "Under 20", [Age]>=20 and <=25, "Between 20 and 25")
AS **Age_Range**
The switch statement evaluates my row heading like this:
1 2 3 4 5 <-- Columns
Under 20 0 0 0 3 2
Between 20 and 25 1 2 0 4 0
Where the value =
Total: Nz(Count(Demo.ID))+0
Okay, all is good so far. However, I am trying to make a left join with the switch statement so ALL of the age ranges will show up, regardless of whether or not there is data. I know I need a table with all of the age ranges, but I am confused.
Here is what I have tried that is currently not working.
Joining the switch statement Age_Range to th开发者_JAVA百科e table Age Range, where the correlating values in the table are the "Under 20" and "Between 20 and 25" strings in the switch. Not working.
Instead of putting the string values in the table, putting the conditions ([Age]<20, etc). However, this fails because in order to put the conditions in the table, it has to be a text field. There is a data mismatch.
Can someone please let me know if this can be done and how?
Thanks,
Make the crosstab a separate query. Then left join that query to your table of item in #1 ("Under 20" and "Between 20 and 25").
精彩评论