Thread: sorting order
View Single Post
  #3  
Old August 19th, 2009, 03:01 PM posted to microsoft.public.access.reports
jmoore[_2_]
external usenet poster
 
Posts: 81
Default sorting order

Thanks so much for your advice. I used the MySortOrder so that all
subreports look the same.

"John Spencer" wrote:

Easiest way would be to add a leading zero to the question values in your
union query. Or you could add another field to the UNION query that is a sort
order field.

SELECT [qYr2ReviewSample].CNTYNAME, [qYr2ReviewSample].ReviewKey, "F01C" as
Question, [F1C] as Answer
FROM [qYr2ReviewSample]
WHERE [F1C] Is Not Null
UNION ALL
....

OR use this and then sort by mySortOrder

SELECT [qYr2ReviewSample].CNTYNAME, [qYr2ReviewSample].ReviewKey, "F1C" as
Question, [F1C] as Answer, 1 as MySortOrder
FROM [qYr2ReviewSample]
WHERE [F1C] Is Not Null
UNION ALL
....
SELECT [qYr2ReviewSample].CNTYNAME, [qYr2ReviewSample].ReviewKey, "F22C" as
Question, [F22C] as Answer, 22
FROM [qYr2ReviewSample]
WHERE [F22C] Is Not Null
UNION ALL
SELECT [qYr2ReviewSample].CNTYNAME, [qYr2ReviewSample].ReviewKey, "F2$C" as
Question, [F22C] as Answer, 24
FROM [qYr2ReviewSample]
WHERE [F2$C] Is Not Null


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

jmoore wrote:
In one of several subreports, I am having problems with the grouping order.
The subreport is based on a crosstab query that is based on a union query.
This subreport is the only one with this problem because it is the only one
where the Question number exceeds a single digit. The grouping is set A to Z
on Question, but does not sort correctly because it is text field with
number. Is there an easy way, or even possible, to have it sort in numerical
order as the other subreports that have only single digits mixed with text?
Here is how the first report I ran sorts (null fields do not display):
F10C, F11C, F1C, F22C, F2C, F5C, F6C, F7C.

I am including the SQL for the 2 queries in case that is helpful.

qYr2Comments_F_Union_Count
SELECT qYr2CommentsSummary_F_Union.CNTYNAME,
qYr2CommentsSummary_F_Union.Question, qYr2CommentsSummary_F_Union.Answer,
Count(qYr2CommentsSummary_F_Union.Answer) AS CountofComments
FROM qYr2CommentsSummary_F_Union
GROUP BY qYr2CommentsSummary_F_Union.CNTYNAME,
qYr2CommentsSummary_F_Union.Question, qYr2CommentsSummary_F_Union.Answer;

qYr2CommentsSummary_f_Union
SELECT [qYr2ReviewSample].CNTYNAME, [qYr2ReviewSample].ReviewKey, "F1C" as
Question, [F1C] as Answer
FROM [qYr2ReviewSample]
WHERE [F1C] Is Not Null
UNION ALL
SELECT [qYr2ReviewSample].CNTYNAME, [qYr2ReviewSample].ReviewKey, "F2C" as
Question, [F2C] as Answer
FROM [qYr2ReviewSample]
WHERE [F2C] Is Not Null
UNION ALL
SELECT [qYr2ReviewSample].CNTYNAME, [qYr2ReviewSample].ReviewKey, "F3C" as
Question, [F3C] as Answer
FROM [qYr2ReviewSample]
WHERE [F3C] Is Not Null
UNION ALL
SELECT [qYr2ReviewSample].CNTYNAME, [qYr2ReviewSample].ReviewKey, "F4C" as
Question, [F4C] as Answer
FROM [qYr2ReviewSample]
WHERE [F4C] Is Not Null
UNION ALL
SELECT [qYr2ReviewSample].CNTYNAME, [qYr2ReviewSample].ReviewKey, "F5C" as
Question, [F5C] as Answer
FROM [qYr2ReviewSample]
WHERE [F5C] Is Not Null
UNION ALL
SELECT [qYr2ReviewSample].CNTYNAME, [qYr2ReviewSample].ReviewKey, "F6C" as
Question, [F6C] as Answer
FROM [qYr2ReviewSample]
WHERE [F6C] Is Not Null
UNION ALL
SELECT [qYr2ReviewSample].CNTYNAME, [qYr2ReviewSample].ReviewKey, "F7C" as
Question, [F7C] as Answer
FROM [qYr2ReviewSample]
WHERE [F7C] Is Not Null
UNION ALL
SELECT [qYr2ReviewSample].CNTYNAME, [qYr2ReviewSample].ReviewKey, "F10C" as
Question, [F10C] as Answer
FROM [qYr2ReviewSample]
WHERE [F10C] Is Not Null
UNION ALL
SELECT [qYr2ReviewSample].CNTYNAME, [qYr2ReviewSample].ReviewKey, "F11C" as
Question, [F11C] as Answer
FROM [qYr2ReviewSample]
WHERE [F11C] Is Not Null
UNION ALL
SELECT [qYr2ReviewSample].CNTYNAME, [qYr2ReviewSample].ReviewKey, "F13C" as
Question, [F13C] as Answer
FROM [qYr2ReviewSample]
WHERE [F13C] Is Not Null
UNION ALL
SELECT [qYr2ReviewSample].CNTYNAME, [qYr2ReviewSample].ReviewKey, "F14C" as
Question, [F14C] as Answer
FROM [qYr2ReviewSample]
WHERE [F14C] Is Not Null
UNION ALL
SELECT [qYr2ReviewSample].CNTYNAME, [qYr2ReviewSample].ReviewKey, "F22C" as
Question, [F22C] as Answer
FROM [qYr2ReviewSample]
WHERE [F22C] Is Not Null
UNION ALL SELECT [qYr2ReviewSample].CNTYNAME, [qYr2ReviewSample].ReviewKey,
"F24C" as Question, [F24C] as Answer
FROM [qYr2ReviewSample]
WHERE [F24C] Is Not Null;