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
Solved

Format number of decimal places in a query

Posted on 2007-04-01
5
2,661 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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
Single Step Macro 4 41
How can I have an Calculator icon for a button? 36 62
Signature required on a report 5 30
Gracefully handling 'Record Locked'  Errors 33 34
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

840 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