Solved

Converting float to currency

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
find SQL job run average duration 24 57
SQL Server Sum Over Multiple Tables 20 35
How come this XML node is not read? 3 31
Need to find substring in SQL 3 14
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

730 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