Solved

Format number of decimal places in a query

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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
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
Comment Utility
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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
No problem.

mx
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
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…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

12 Experts available now in Live!

Get 1:1 Help Now