Solved

Format number of decimal places in a query

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
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…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

813 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now