Solved

Converting float to currency

Posted on 2002-03-18
4
1,653 Views
Last Modified: 2012-05-04
Is there a way to convert float to currency within a SQL query similar to the format function in VB where it adds a $ and puts commas in the correct places.

I have a table which has MASUM as a float and MASTRSUM as char(20).

I perform a query

INSERT INTO CT_SALES
 ( OpSegment, MAYear, MAQuarter, MAMonth, MASALES)
SELECT "dbo"."CustType"."Description" as OpSegment ,
DatePart(year,"dbo"."TimeInfo"."DATEVALUE") as MAYear ,
NULL,
NULL,
SUM("dbo"."orderinfo"."Extended_Price") As MASALES
FROM
"dbo"."orderinfo", "dbo"."CustInfo", "dbo"."CustType", "dbo"."TimeInfo"
WHERE ("dbo"."CustInfo"."MATYPE"="dbo"."CustType"."MATYPE") AND
("dbo"."CustInfo"."DCODE"="dbo"."orderinfo"."DCODE") AND
("dbo"."CustInfo"."CUSNR"="dbo"."orderinfo"."CUSNR") AND
("dbo"."orderinfo"."DDATE"="dbo"."TimeInfo"."DDATE")
GROUP BY "dbo"."CustType"."Description" ,
DatePart(year,"dbo"."TimeInfo"."DATEVALUE")

I would like in this query also add information in the MASTRSUM field which is in currency format. Currently I use a VB program to perform the FORMAT conversion.
0
Comment
Question by:rian
  • 2
4 Comments
 
LVL 4

Expert Comment

by:TheSpirit
ID: 6879293
Take a look at convert in Books on line, this may provide the info you need, but I don't think it will start adding $ symbols in the output.
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 6880690
You could use:

cast(cast(MASUM as money) as varchar)

It doesn't add any currency symbol, though (at least not on my computer). It only rounds the value to two decimals...
0
 

Author Comment

by:rian
ID: 6880715
But there is still no way to add the comma's and the dollar sign to a money value.
0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 50 total points
ID: 6880763
The commas can be handled by convert, but the dollar sign has to be added as a string:

'$'+convert(varchar,cast(Account as money),1)

I guess that MS-SQL has realised that there are other currencies out there... ;)
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
backup job space check 4 44
SQL USE DATABASE VARIABLE 5 27
Get Next number from Stored Procedure 8 22
SQL Recursion schedule 13 14
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

856 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