A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Union query not displaying select statement



 
 
Thread Tools Display Modes
  #1  
Old April 27th, 2010, 08:50 PM posted to microsoft.public.access.queries
e133
external usenet poster
 
Posts: 3
Default Union query not displaying select statement

I have a union query which provides column totals for a detail query.
Everything works as expected but for some reason when I run the query the
results will not always display the last select statement - "Percent of
total" row. The odd occurence is if I run the query with a filter that limits
the records to one viewable page in datasheet view the "percent of total" row
is displayed. If the query output is more than one viewable page the "percent
of total" row does not display.
Also, if I remove "all" from the last union statement the "percent of total"
row will display with all filters but the ordering in not correct. I need to
have the three union selects as the last three rows - without the "all" they
are ordered with the name column.

Below is the sql. Any help on getting the "percent of total" to always
display or the ordering corrected is appreciated.

PARAMETERS [Enter Start Date] DateTime, [Enter End Date] DateTime;
SELECT [Create].[Vendor Name], Count([Create].[Nbr]) AS POs,
Sum(Abs([LOS]='Late')) AS Lates, Sum(Abs([LOS]='NoShow')) AS [No Shows]
FROM [Create]
WHERE ((([Create].[Terms])="P") AND (([Create].[Date]) Between [Enter Start
Date] And [Enter End Date]) AND (([Create].Dept)=[Enter Dept]))
GROUP BY [Create].[Vendor Name]
UNION ALL
SELECT "Dept Total", Sum(POs), Sum(Lates), Sum([No Shows])
FROM [Department Summary]
UNION ALL
SELECT "All Dept Total", Sum(POs), Sum(Lates), Sum([No Shows])
FROM [Prepaid Summary]
UNION ALL
SELECT "Percent of Total", Round(((Sum(POs)/(Select Sum(POs) From [Prepaid
Summary]))*100),2), Round(((Sum(Lates)/(Select Sum(Lates) From [Prepaid
Summary]))*100),2), Round(((Sum([No Shows])/(Select Sum([No Shows]) From
[Prepaid Summary]))*100),2)
FROM [Department Summary];




  #2  
Old April 27th, 2010, 11:31 PM posted to microsoft.public.access.queries
Tore
external usenet poster
 
Posts: 12
Default Union query not displaying select statement


You should add "order by" statement after the last union select, at the
bottom of your statement.

When I need some special ordering in a union I often add a sort field:

Select 1 as sortfield, field2, field3 ......
union
Select 2 as sortfield, ...........
union
Select 3 as sortfield, ........

order by Sortfield

Disappearance of last record(s) I cannot explain. May be in some cases it
does not return any record at all? By using a sortfield you can force it to
appear at the top and check out if it has something to do with its position
in the list.

Regards
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:49 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.