?
Solved

Format number of decimal places in a query

Posted on 2007-04-01
5
Medium Priority
?
2,682 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

777 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