Solved

Format number of decimal places in a query

Posted on 2007-04-01
5
2,673 Views
Last Modified: 2008-01-09
I am trying to create the union of two crosstab queries. The first collates the data by week and all the results are to two decimal places.

The second query (qryAveragor) calculates the average by Year and so the average is to multiple decimal places. For this query I am able to fix the display in design view by changing the format to Fixed.

However when I unite them I the averages display to multiple decimal places. Is there any way of defining the number of decimal places to appear in the result of my union query? Following is the code I am using for the UNION query.
select * from qryComparator
UNION ALL
Select * from qryAveragor;

The code of qryAveragor is
PARAMETERS [Forms]![frmMain]![CboCat] Value;
TRANSFORM Avg(tblSales.Value) AS AvgOfValue
SELECT tlCategories.CatDesc, "Average " & Year([salesdate]) AS [Year]
FROM tblSiteData INNER JOIN (tblSales INNER JOIN tlCategories ON tblSales.Cat = tlCategories.Cat) ON tblSiteData.Ident = tblSales.Ident
WHERE (((tblSales.Cat)=[Forms]![frmMain]![CboCat]))
GROUP BY tlCategories.CatDesc, "Average " & Year([salesdate])
PIVOT [LocnName] & " (" & tblsales.Ident & ")";
0
Comment
Question by:Rob4077
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 35

Expert Comment

by:Raynard7
ID: 18834405
you can set the number of decimal places using a format statement,

ie

Format(Avg(tblSales.Value), "0.00")

will give it to you with 2 decimal places.

but you would have to remove the select * but do each field to define this.
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 18834410
>TRANSFORM Avg(tblSales.Value) AS AvgOfValue
Try changing this line to:

TRANSFORM FormatNumber(Avg(tblSales.Value),2) AS AvgOfValue
                                                                            ^--- Number of decimal places
0
 
LVL 75
ID: 18834415
If this query is driving a form or report, then for that field, you can set the Format property of the text box to

Standard, and Decimal Places = 2

mx
0
 

Author Comment

by:Rob4077
ID: 18834436
Thanks guys.
Raynard7, because of the structure of my query I can't list all the variable so yours is not the right option in this case.
mx, your solution will work on the form but on this occasion I am just setting up a quick view so I wanted it to work on the query
mbizup, your solution achieved my goal. Thanks
0
 
LVL 75
ID: 18834440
No problem.

mx
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question