Solved

Converting number to 2-digit in MS Query

Posted on 2011-09-25
5
216 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 …
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
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…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

758 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

20 Experts available now in Live!

Get 1:1 Help Now