Solved

Converting float to currency

Posted on 2002-03-18
4
1,648 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

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

Suggested Solutions

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

707 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

18 Experts available now in Live!

Get 1:1 Help Now