Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formating a number to "$#,##0;($#,##0)"

Status
Not open for further replies.

Ginka

Programmer
Mar 18, 2005
54
MX
I have in a stored procedure a query that returns a number, but I need it formatted like if it where money.

How can I do that?

something like this:

SELECT MyField
FROM AnyTable

MyField is the result of some real and integer calculations and I want it like this $1,256.23
 
Try this:

Code:
SELECT '$' + CONVERT(VARCHAR(10),(CONVERT(MONEY, 125623, 1)))

The CONVERT(MONEY, <value>, 1) uses the style 1 to add the decimal and commas. You have to then make it a string and concatenate the dollar sign.

Refer to the BOL for CONVERT.

-SQLBill

Posting advice: FAQ481-4875
 
Thanks SQLBill, it is working with the dollar sign, but the comma is missing.

Any other suggestion?
 
Okay, after looking at the BOL again...you have to start with a MONEY value.

Code:
DECLARE @myval MONEY
SET @myval = 123456
SELECT '$' + CONVERT(VARCHAR(20), @myval, 1)

-SQLBill

Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top