Solved

Converting number to 2-digit in MS Query

Posted on 2011-09-25
5
230 Views
Last Modified: 2012-05-12

I am working on an MS Query and have the following code:

SELECT TempTable.Category, Sum(TempTable.`Dec 31, 09`), Sum(TempTable.`Dec 31, 10`), Sum(TempTable.`Jul 31, 11`)
FROM TempTable TempTable
WHERE (TempTable.Category<>'')
GROUP BY TempTable.Category

It produces what I expected and hoped for except for the extra long numbers.  Can someone tell me how to convert the number to 2 decimal places with commas as thousands separators?
0
Comment
Question by:BBlu
  • 3
5 Comments
 
LVL 18

Accepted Solution

by:
Jerry Miller earned 125 total points
ID: 36596795
I would format the target cells with 2 decimals and use the ROUND function to make sure that your data is consistant.

ROUND(Sum(TempTable.`Dec 31, 10`),2)
0
 
LVL 13

Assisted Solution

by:lee555J5
lee555J5 earned 125 total points
ID: 36596876
If formatting the target cells is not an option in your project, try the Format command in your SQL statement. Look up the command in the help to see examples that may fit your need.

Lee
SELECT TempTable.Category, Format(Sum(TempTable.`Dec 31, 09`), "currency")
FROM TempTable TempTable
WHERE (TempTable.Category<>'')
GROUP BY TempTable.Category

Open in new window

0
 

Author Comment

by:BBlu
ID: 36597254
Thank you both, when I tried the Round() function, it seemed to work (code attached).  But when I try to do the currency version, which I need I guess if I want to include commas for thousands separators, I get an error.  Any idea why?

 MS Query-Format Error
0
 

Author Comment

by:BBlu
ID: 36597272
Never mind..it looks like II need to make 'currency' single quotes.. that worked.
0
 

Author Closing Comment

by:BBlu
ID: 36597306
Thank you both very much!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

930 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

10 Experts available now in Live!

Get 1:1 Help Now